我想让自动机使用lex和yacc来接受下面的正则表达式。正则表达式是R= (ab + a)*。
有人能帮我用lex和yacc构建这个自动机吗?
谢谢。
发布于 2009-12-24 11:28:13
首先浮现在脑海中的是这样的东西。不是完整的程序,而是一些可以让你入门的东西:
扫描仪(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 */;
%%解析器(Yacc):
commands: /* empty */
| commands command
{ printf("found a (ab + a)* pattern"); }
command:
ab
|
a
;
ab: TOKENA TOKENB
;
a: TOKENA
;我不能完全确定语法是否有效,或者是否有任何缩减冲突。
https://stackoverflow.com/questions/1956462
复制相似问题