%{ #include #include #include #include #include "funkcije.hpp" #define YYDEBUG 1 using namespace std; void yyerror(string s) { cerr << s << endl; exit(EXIT_FAILURE); } extern int yylex(); map tablica; %} %token function_token sin_token cos_token %token id_token %token num_token %left '+' '-' %left '*' '/' %nonassoc '\'' %union { char c; double d; Funkcija *f; } %type E %% Program: Program Naredba '\n' { } | Naredba '\n' { } ; Naredba: function_token id_token '=' '"' E '"' { map::iterator i = tablica.find($2); if (i != tablica.end()) yyerror("Funckija vec postoji"); tablica[$2] = $5; } | id_token { map::iterator i = tablica.find($1); if (i == tablica.end()) yyerror("Funkcija nije definisana"); i->second->ispisi(); cout << endl; } | id_token '\'' { map::iterator i = tablica.find($1); if (i == tablica.end()) yyerror("Funkcija nije definisana"); i->second->izvod()->ispisi(); cout << endl; //TODO: brisanje izvoda } ; 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; } | num_token { $$ = new Konstanta($1); } | sin_token '(' E ')' { $$ = new Sin($3); } | cos_token '(' E ')' { $$ = new Cos($3); } | 'x' { $$ = new Identicka(); } | E '\'' { $$ = $1->izvod(); //TODO: delete $1; } ; %% int main() { //yydebug = 1; yyparse(); return 0; }