I want to make the automata to accept following regular expression using lex and yacc. The regular expression is R = (ab + a)* .
Can anyone help me to construct this automata using lex and yacc.
Thanks.
I want to make the automata to accept following regular expression using lex and yacc. The regular expression is R = (ab + a)* .
Can anyone help me to construct this automata using lex and yacc.
Thanks.
First thing that comes to mind is something like this. Not complete programs, but something to get you started:
The scanner(lex):
%%
a return TOKENA; /* for an a in the input */
b return TOKENB; /* for a b in the input */
\n /* ignore end of line */;
[ \t]+ /* ignore whitespace */;
%%
The parser(yacc):
commands: /* empty */
| commands command
{ printf("found a (ab + a)* pattern"); }
command:
ab
|
a
;
ab: TOKENA TOKENB
;
a: TOKENA
;
I'm not completely sure if the grammar works or has any reduction conflicts.