%{ #include #include #include #include using namespace std; extern int yylex(); void yyerror(string s) { cerr << s << endl; exit(EXIT_FAILURE); } %} %token value_token sin_token cos_token %token num_token %type E %union { double d; } %left '+' '-' %left '*' '/' %% Program: Program Naredba | Naredba ; Naredba: value_token '"' E '"' '\n' { cout << $3 << endl; } ; E : E '+' E { $$ = $1 + $3; } | E '-' E { $$ = $1 - $3; } | E '*' E { $$ = $1 * $3; } | E '/' E { $$ = $1 / $3; } | '(' E ')' { $$ = $2; } | sin_token '(' E ')' { $$ = sin($3); } | cos_token '(' E ')' { $$ = cos($3); } | num_token { $$ = $1; } ; %% int main() { yyparse(); return 0; }