%{ #include #include #include #include "regex.hpp" #include #include #define YYDEBUG 1 using namespace std; void yyerror(string s) { cerr << s << endl; exit(EXIT_FAILURE); } extern int yylex(); map definicije; %} %union { char c; RegEx *r; vector *v; } %token basic_token definition_token maxlen_token %token slovo_token id_token %type E T F %type Niz %% Program: Program Naredba '\n' { } | Naredba '\n' { } ; Naredba: basic_token E { try { $2->basic(); } catch (const char *s) { yyerror(s); } cout << endl; delete $2; } | definition_token id_token '=' E { if (definicije.find($2) != definicije.end()) yyerror("Redefinicije nisu dozvoljene"); definicije[$2] = $4; } | maxlen_token E { try { int tmp = $2->maxlen(); if (tmp < 0) cout << "Inf" << endl; else cout << tmp << endl; delete $2; } catch (const char *s) { yyerror("Ne postoji definicija"); } } ; E: E '|' T { $$ = new Disjunkcija($1, $3); } | T { $$ = $1; } ; T: T F { $$ = new Konkatenacija($1, $2); } | F { $$ = $1; } ; F: F '*' { $$ = new Klini($1); } | slovo_token { $$ = new Slovo($1); } | '(' E ')' { $$ = $2; } | F '+' { $$ = new Plus($1); } | '[' Niz ']' { $$ = new KarakterskaKlasa(*$2); delete $2; } | '{' id_token '}' { $$ = new Definicija($2); } ; Niz: Niz slovo_token { $$ = $1; $$->push_back($2); } | slovo_token { $$ = new vector(); $$->push_back($1); } ; %% int main() { //yydebug = 1; yyparse(); return 0; }