[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

problem with flex



i was doing a lex program for token identification
CODE:
%{
#include<stdio.h>
#include<math.h>
%}
DIGIT [0-9]
ID [A-Za-z]+
WS [\n\t" "]
%%
{DIGIT}+ {printf("Integer:%d\n",atoi(yytext));}
{DIGIT}+"."{DIGIT}+ {printf("Float:%g\n",atof(yytext));}
[a-z]+"."h {printf("Header File:%s\n",yytext);}
#include|printf|if|else|else" "if|do|while|for|case|scanf|void|int|float|char {printf("Keyword:%s\n",yytext);}
{ID} {printf("Identifier:%s",yytext);}
"/*"{WS}*{ID}{WS}*"*/" {printf("\nComment:%s",yytext);}
"++" {printf("Increment:%s\n",yytext);}
"--" {printf("Decrement:%s\n",yytext);}
"%" ("d"|"s"|"f"|"c"|"u"|"g") {printf("Format Specifier:%s",yytext);}
">"|"<"|"<="|">="|"<>"|"==" {printf("Relational Operator:%s",yytext);}
[\t]+ {printf("\nUnrecognised Character:%s",yytext);}
%%
main(int argc, char **argv)
{
       if(argc>1)
            yyin=fopen(argv[0],"r");
        else
            yyin=stdin;
        yylex();
}
Executing this code gives the result:
debian:~# lex idtoken.l -ll
lex: can't open -ll
/usr/bin/m4:stdin:2550: ERROR: end of file in string
debian:~#

what do i do to solve this problem???

Reply to: