如何将lex输入检查为单个输入

时间:2015-04-22 06:27:59

标签: flex-lexer lex

我制作了一个lex文件,如下所示:

%%
[\t\n]
"if" {printf("IF_TOKEN\n");}
"else" {printf("ELSE_TOKEN\n");}
"while" {printf("WHILE_TOKEN\n");}
"FOR" {printf("FOR_TOKEN\n");}
"BREAK" {printf("BREAK_TOKEN\n");}
"float" {printf("FLOAT_TOKEN\n");}
"int" {printf("INT_TOKEN\n");}
"long" {printf("LONG_TOKEN\n");}
"return" {printf("RETURN_TOKEN\n");}
"defFunction" {printf("DEFFUNCTION_TOKEN\n");}
"defClass" {printf("DEFCLASS_TOKEN\n");}
"\(" {printf("PAROPEN_TOKEN\n");}
"\)" {printf("PARCLOS_TOKEN\n");}
"\{" {printf("CBROPEN_TOKEN\n");}
"\}" {printf("CBRCLOS_TOKEN\n");}
"<" {printf("LESSTHN_TOKEN\n");}
">" {printf("GRTRTHN_TOKEN\n");}
"=" {printf("EQUALTO_TOKEN\n");}
"!=" {printf("NEQUALTO_TOKEN\n");}
"\+" {printf("SUM_TOKEN\n");}
"-" {printf("MINUS_TOKEN\n");}
"\*" {printf("STAR_TOKEN\n");}
"\/" {printf("SLASH_TOKEN\n");}
"%" {printf("REMAIN_TOKEN\n");}
"\[" {printf("BRAOPEN_TOKEN\n");}
"\]" {printf("BRACLOS_TOKEN\n");}
";" {printf("SEMICOL_TOKEN\n");}
[-]?[1-9][0-9]* {printf("NUMBER\n");}
[A-Za-z&_$][A-Za-z$_]* {printf("ID\n");}
. {printf("ERROR");}

%%
int yywrap (void) {
return 1;
}
int main (int argc, char** argv) {
   yylex();
   return 0;
}

如果我在编译.l文件后将125apple作为此lex文件的输入,它应该打印错误但它打印     数     ID 我如何才能将125apple作为单一输入?

0 个答案:

没有答案