Why does Flex say this is an “unrecognized rule”?

梦想的初衷 提交于 2019-12-08 01:41:21

问题


In the following:

space           ([ \t\f\r])+         
opt_space       ([ \t\f\r])*         
cpp             ^{opt_space}#{opt_space} 
word            [A-Za-z_][A-Za-z_0-9]*
arg_macro       {cpp}define{space}{word}
/*arg_macro       ^{opt_space}#{opt_space}define{space}{word}*/

%%
{arg_macro}     ;
%%

I get an error message

test.l:9: unrecognized rule

If I uncomment the second version of arg_macro and comment the first one, the error message goes away.

Any ideas why?


回答1:


If you remove the ^ from the cpp definition, and place it in the arg_macro definition, then it's happy.

space           ([ \t\f\r])+
opt_space       ([ \t\f\r])*
cpp             {opt_space}#{opt_space}
word            [A-Za-z_][A-Za-z_0-9]*
arg_macro       ^{cpp}define{space}{word}


来源:https://stackoverflow.com/questions/3243011/why-does-flex-say-this-is-an-unrecognized-rule

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!