%{ #include #include #include #include #define YYDEBUG 1 using namespace std; extern int yylex(); void yyerror(string s) { cerr << s << endl; exit(EXIT_FAILURE); } map tablica; %} %union { int i; string *s; } %token pocetak_token kraj_token ispisi_token mod_token %token broj_token %token string_token id_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; } | id_token ':' '=' E { tablica[*$1] = $4; delete $1; } ; E: E '+' E { $$ = $1 + $3; } | E '*' E { $$ = $1 * $3; } | E mod_token E { $$ = $1 % $3; } | '(' E ')' { $$ = $2; } | broj_token { $$ = $1; } | id_token { $$ = tablica[*$1]; } ; %% int main() { //yydebug = 1; yyparse(); return 0; }