CD LAB Lex

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

LAB ASSIGNMENT – 3

Q. Implement the complete lexical analyser using lex tool.

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 :

You might also like