在以下代码中,它是 C 语言的词法识别器:
%{
#include <stdio.h>
void showToken(char*);
%}
%option yylineno
%option noyywrap
digit ([0-9])
letter ([a-zA-Z])
%%
letter(letter | digit)* showToken("id");
(digit)(digit)*(.(digit)(digit)*)? showToken("num");
[(),:;.] printf("%c",yytext[0]);
[ \n]
(==|<>|<|<=|>|>=) showToken("relop");
(+|-) showToken("addop");
(*|/) showToken("mulop");
(=) showToken("assign");
(&&) showToken("and");
(||) showToken("or");
(!) showToken("not");
. {
printf("Lexical Error");
exit(0);
}
%%
void showToken(char* name){
printf("<%s,%s>",name,yytext);
}
%%
我收到以下错误,为什么会发生这种情况我认为我正确编写了代码!我对代码做了太多更改,但无法编译。
~/hedor>lex -t lexical.l > lexical.c
lexical.l:13: unrecognized rule
lexical.l:17: unrecognized rule
lexical.l:17: unrecognized rule
lexical.l:17: unrecognized rule
lexical.l:17: unrecognized rule
lexical.l:17: unrecognized rule
lexical.l:18: unrecognized rule
lexical.l:18: unrecognized rule
lexical.l:18: unrecognized rule
lexical.l:18: unrecognized rule
lexical.l:18: unrecognized rule
lexical.l:21: unrecognized rule
lexical.l:21: unrecognized rule
lexical.l:21: unrecognized rule
lexical.l:21: unrecognized rule