我有一个像这样的 lex 文件
%{
#include "y.tab.h"
%}
%%
"print" {return print;}
"exit" {return exit_command;}
[a-zA-Z] {yylval.id = atoi(yytext); return identifier;}
[0-9]+ {yylval.num = atoi(yytext);} return number;}
[ \t\n] ;
[-+=;] {return yytext[0];}
. {ECHO; yyerror("unexpected charater");}
%%
int yywrap(void){return 1;}
但是当我尝试运行 lex filename.l
我收到以下错误
filename.l:16: EOF encountered inside an action
任何人都可以看到任何错误
最佳答案
您的数字模式( [0-9]+
)有一个额外的 }
其行为令人困惑(也令人困惑 flex
)。
关于lex - 文件名.l :16: EOF encountered inside an action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29711090/