%{ #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; %} %union { Funkcija *f; double d; char c; } %token function_token sin_token cos_token %token id_token %token num_token %type E %left '+' '-' %left '*' '/' %% Program: Program Naredba '\n' | Naredba '\n' ; Naredba: function_token id_token '=' '"' E '"' { map::iterator i = tablica.find($2); if (i != tablica.end()) delete i->second; tablica[$2] = $5; } | id_token { map::iterator i = tablica.find($1); if (i == tablica.end()) yyerror("Nedefinisana fja"); i->second->ispisi(); cout << 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); } | sin_token '(' E ')' { $$ = new Sin($3); } | cos_token '(' E ')' { $$ = new Cos($3); } | '(' E ')' { $$ = $2; } | num_token { $$ = new Konstanta($1); } | 'x' { $$ = new IdFja(); } ; %% int main(int argc, char **argv) { yyparse(); for (map::iterator i = tablica.begin(); i != tablica.end(); i++) delete i->second; return 0; }