%{ #include #include #include #include "izrazi.hpp" #include "naredbe.hpp" using namespace std; void yyerror(string s) { cerr << s << endl; exit(EXIT_FAILURE); } extern int yylex(); %} %token ispisi_token mod_token kraj_token pocetak_token %token num_token %token string_token %type E %type Naredba Blok %type NizNaredbi %union { int d; Izraz* i; Naredba* n; string *s; vector *v; } %left '+' '-' %left '*' '/' mod_token %% 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); } ; 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); } ; %% int main() { yyparse(); return 0; }