%{ #include #include #include using namespace std; extern int yylex(); void yyerror(string s) { cerr << s << endl; exit(EXIT_FAILURE); } %} %union { int i; string *s; } %token pocetak_token kraj_token ispisi_token mod_token %token broj_token %token string_token %left '+' %left '*' mod_token %type E %% Program: Blok '.' ; Blok: pocetak_token NizNaredbi kraj_token ; NizNaredbi: NizNaredbi ';' Naredba | Naredba ; Naredba: ispisi_token '(' string_token ')' { cout << *$3 << endl; delete $3; } | ispisi_token '(' E ')' { cout << $3 << endl; } ; E: E '+' E { $$ = $1 + $3; } | E '*' E { $$ = $1 * $3; } | E mod_token E { $$ = $1 % $3; } | broj_token { $$ = $1; } ; %% int main() { yyparse(); return 0; }