cal.y

来自「lex files for given decription used as 」· Y 代码 · 共 132 行

Y
132
字号
%{ #include <stdio.h>#include <math.h>#define YYSTYPE doubleextern int yylex(void);%}%token NUMBER%token LAST%left '+' '-'%left '*' '/'%left '^'%left NEGATIVE%left COS EXP SIN SQRT TAN%%list:    |    list '\n'    |    list expr '\n'           { printf("%.8g\n",(double)$2);}    ;     expr:     term                 { $$ = $1;         }    |     expr '+' expr            { $$ = $1 + $3;    }    |     expr '-' expr            { $$ = $1 - $3;    }    |     expr '*' expr            { $$ = $1 * $3;    }    |     expr '/' expr            { $$ = $1 / $3;    }    |     expr '^' expr            { $$ = pow($1,$3); }    |     '-' expr  %prec NEGATIVE { $$ = - $2;       }    |     COS   term               { $2=$2*3.14159265;$2=$2/180;$$ = cos($2);    }    |     EXP   term               {$$ = exp($2);    }    |     SIN   term               { $2=$2*3.14159265;$2=$2/180;$$ = sin($2);    }    |     SQRT  term               { $$ = sqrt($2);   }    |     TAN   term               { $2=$2*3.14159265;$2=$2/180;$$ = tan($2);    }    ;term:     NUMBER                   { $$ = $1;         }    |     '(' expr ')'             { $$ = $2;         }    ;%%#include <stdlib.h>#include <string.h>#include <unistd.h>int yyerror(const char *s){    printf("\nError Occured\n");    return 0;}int yywrap(void){	return 1;}main(){	yyparse();	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?