%{ #include #include #include #include #include "regex.hpp" #include using namespace std; void yyerror(string s) { cerr << s << endl; exit(EXIT_FAILURE); } extern int yylex(); map definicije; %} %union { char c; int i; vector *v; RegEx *r; } %token basic_token definition_token maxlen_token minstr_token %token char_token id_token %token num_token %type NizKaraktera %type E T F %% Program: Program Naredba '\n' | Naredba '\n' ; Naredba: basic_token E { try { $2->basic(); cout << endl; delete $2; } catch (const char *s) { yyerror(s); } } | definition_token id_token '=' E { if (definicije.find($2) != definicije.end()) yyerror("Nije dozvoljena redefinicija regularne definicije"); definicije[$2] = $4; } | maxlen_token E { int tmp; try { tmp = $2->maxlen(); } catch (const char *s) { yyerror(s); } if (tmp < 0) cout << "Inf" << endl; else cout << tmp << endl; } | minstr_token E { string s; try { s = $2->minstr(); } catch (const char *s) { yyerror(s); } cout << s << endl; } ; E: E '|' T { $$ = new Disjunkcija($1, $3); } | T { $$ = $1; } ; T: T F { $$ = new Konkatenacija($1, $2); } | F { $$ = $1; } ; F: F '*' { $$ = new Klini($1); } | F '+' { $$ = new Plus($1); } | F '?' { $$ = new Upitnik($1); } | char_token { $$ = new Slovo($1); } | '(' E ')' { $$ = $2; } | '[' NizKaraktera ']' { $$ = new KarakterskaKlasa(*$2); delete $2; } | '{' id_token '}' { $$ = new Definicija($2); } | F num_token { $$ = new VisestrukoPojavljivanje($1, $2); } ; NizKaraktera: NizKaraktera char_token { $$ = $1; $$->push_back($2); } | char_token { $$ = new vector(); $$->push_back($1); } ; %% int main() { yyparse(); for (map::iterator tmp = definicije.begin(); tmp != definicije.end(); tmp++) delete tmp->second; return 0; }