Professional Documents
Culture Documents
CD LAB Lex
CD LAB Lex
CD LAB Lex
Program :
%{
int count=0;
%}
%%
"int"|"float"|"char"|"double"|"while"|"for"|"do"|"if"|"break"|"continue"|"void"|"switch"|"case"|"long"|
"struct"|"const"|"typedef"|"return"|"else"|"goto" {printf("%s is a Keyword.\n",yytext);}
[a-zA-Z][a-zA-Z0-9]* {printf("%s is an Identifier.\n",yytext);}
"+"|"-"|"*"|"/"|"="|"=="|"+="|"-=" {printf("%s is an Operator.\
n",yytext);} [0-9]+ {printf("Integer Number.\n");}
[0-9]+.[0-9]+ {printf("%s is a Real Number.\n",yytext);}
%%
int yywrap(void) {}
int main() {
yylex();
return 0;
}
Output :