%{ #include #include #include #include #include "funkcije.hpp" #include using namespace std; extern int yylex(); void yyerror(string s) { cerr << s << endl; exit(EXIT_FAILURE); } map tablica; %} %token value_token sin_token cos_token function_token %token num_token %token id_token %type E %union { char c; double d; Funkcija *f; } %left '+' '-' %left '*' '/' %left '\'' %% Program: Program Naredba | Naredba ; Naredba: function_token id_token '=' '"' E '"' '\n' { tablica[$2] = $5; } | id_token '\n' { map::iterator tmp = tablica.find($1); if (tmp == tablica.end()) yyerror(string("Nepostojeca fja ") + $1); tmp->second->ispisi(); cout << endl; } | id_token '\'' '\n' { map::iterator tmp = tablica.find($1); if (tmp == tablica.end()) yyerror(string("Nepostojeca fja ") + $1); Funkcija *izvod = tmp->second->izvod(); izvod->ispisi(); cout << endl; delete izvod; } | id_token '[' num_token ']' '\n' { map::iterator tmp = tablica.find($1); if (tmp == tablica.end()) yyerror(string("Nepostojeca fja ") + $1); cout << tmp->second->vrednost($3) << endl; } ; E : E '+' E { $$ = new Zbir($1, $3); } | E '-' E { $$ = new Razlika($1, $3); } | E '*' E { $$ = new Proizvod($1, $3); } | E '/' E { $$ = new Kolicnik($1, $3); } | '(' E ')' { $$ = $2; } | E '\'' { $$ = $1->izvod(); delete $1; } | sin_token '(' E ')' { $$ = new Sin($3); } | cos_token '(' E ')' { $$ = new Cos($3); } | num_token { $$ = new Konstanta($1); } | 'x' { $$ = new Identicka(); } ; %% int main() { yyparse(); return 0; }