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