【发布时间】:2014-05-21 01:05:16
【问题描述】:
我正在用 lex 编写一个程序,它给了我以下错误:
LexInput.l:12:无法识别的规则
第 12 行是:\"([^\042\134]|"\"(.|[\n]))*\" printf("string : %s\n", yytext);
这是我的代码:
%{
#include <stdio.h>
%}
L [a-zA-Z]
D [0-9]
%%
{L}({L}|{D})* printf("id : %s\n", yytext);
[a-zA-Z_][a-zA-Z0-9_]* printf("C id : %s\n", yytext);
[+-]?[0-9]+ printf("integer : %s\n", yytext);
[0-9]+"."[0-9]+(e[+-]?[0-9]+)? printf("real : %s\n", yytext);
\"([^\042\134]|"\"(.|[\n]))*\" printf("string : %s\n", yytext);
"/*"([^*]|"*"+[^*)])*"*"+"/" printf("text comment : /* ... */\n");
"//".* printf("line comment : // ... \n");
"\n" |
. ;
%%
int yywrap()
{
return 1;
}
void main()
{
yylex();
}
【问题讨论】:
标签: lex