%{ #include #include #include #include #include "izrazi.hpp" #include "naredbe.hpp" #include #define YYDEBUG 1 using namespace std; void yyerror(string s) { cerr << s << endl; exit(EXIT_FAILURE); } extern int yylex(); map tablica; %} %token ispisi_token pocetak_token kraj_token mod_token %token num_token %token string_token id_token %left '+' '-' %left '*' '/' mod_token %type E %type Naredba Blok %type NizNaredbi %union { int d; Izraz *i; Naredba *n; string *s; vector *v; } %% Program: Blok '.' { $1->izvrsi(); delete $1; } ; Blok: pocetak_token NizNaredbi kraj_token { $$ = new Blok(*$2); delete $2; } ; NizNaredbi: NizNaredbi ';' Naredba { $$ = $1; $$->push_back($3); } | Naredba { $$ = new vector(); $$->push_back($1); } ; Naredba: ispisi_token '(' string_token ')' { $$ = new IspisS(*$3); delete $3; } | ispisi_token '(' E ')' { $$ = new IspisE($3); } | id_token ':' '=' E { $$ = new Dodela(*$1, $4); delete $1; } ; 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 mod_token E { $$ = new Mod($1, $3); } | '(' E ')' { $$ = $2; } | num_token { $$ = new Konstanta($1); } | id_token { $$ = new Promenljiva(*$1); delete $1; } ; %% int main() { //yydebug = 1; yyparse(); return 0; }