%{ #include #include #include #include #define YYDEBUG 1 #include "reg_izrazi.hpp" using namespace std; extern int yylex(); void yyerror(string s) { cerr << s << endl; exit(EXIT_FAILURE); } map definicije; %} %union { RegEx *r; char c; string *s; int i; } %type E E1 E2 %type Niz %token basic_token definition_token maxlen_token minstr_token %token slovo_token %token broj_token %token id_token %left '*' '+' %% Program: Program Naredba | Naredba ; Naredba: basic_token E '\n' { cout << $2->basic() << endl; delete $2; } | definition_token id_token '=' E '\n' { map::iterator tmp = definicije.find($2); if (tmp != definicije.end()) { delete tmp->second; tmp -> second = $4; } else definicije[$2] = $4; } | maxlen_token E '\n' { int tmp = $2->maxlen(); if (tmp < 0) cout << "Inf" << endl; else cout << tmp << endl; delete $2; } | minstr_token E '\n' { cout << $2->minstr() << endl; } ; E: E '|' E1 { $$ = new Disj($1, $3); } | E1 { $$ = $1; } ; E1 : E1 E2 { $$ = new Concat($1, $2); } | E2 { $$ = $1; } ; E2: E2 '*' { $$ = new Iter($1); } | slovo_token { $$ = new Char($1); } | '(' E ')' { $$ = $2; } | E2 '+' { $$ = new Plus($1); } | '[' Niz ']' { $$ = new CharClass(*$2); delete $2; } | E2 '?' { $$ = new QuestionMark($1); } | E2 broj_token { $$ = new IterN($1, $2); } | '{' id_token '}' { $$ = new Definition($2); } ; Niz: Niz slovo_token { char tmp[2]; tmp[0] = $2; tmp[1] = '\0'; $$ = new string(*$1 + string(tmp)); delete $1; } | slovo_token { char tmp[2]; tmp[0] = $1; tmp[1] = '\0'; $$ = new string(tmp); } ; %% int main() { //yydebug = 1; yyparse(); return 0; }