%{ #include #include #include #include "reg_izrazi.hpp" using namespace std; extern int yylex(); void yyerror(string s) { cerr << s << endl; exit(EXIT_FAILURE); } %} %union { RegEx *r; char c; string *s; int i; } %type E E1 E2 %type Niz %token basic_token %token slovo_token %token broj_token %% Program: Program Naredba | Naredba ; Naredba: basic_token E '\n' { cout << $2->basic() << endl; delete $2; } ; 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, $3); } ; 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() { yyparse(); return 0; }