%{
int COMMENT=0;
%}
identifier [a-zA-Z][a-zA-Z0-9]*
%%
#.* {printf("\n%s is a preprocessor directive",yytext);}
int |
char |
double |
while |
for |
struct |
typedef |
do |
if |
break |
continue |
void |
switch |
return |
else |
goto {printf("\n\t%s is a keyword",yytext);}
"/*" {COMMENT=1;}{printf("\n\t %s is a COMMENT",yytext);}
{identifier}\( {if(!COMMENT)printf("\nFUNCTION \n\t%s",yytext);}
\{ {if(!COMMENT)printf("\n BLOCK BEGINS");}
\} {if(!COMMENT)printf("BLOCK ENDS ");}
{identifier}(\[[0-9]*\])? {if(!COMMENT) printf("\n %s IDENTIFIER",yytext);}
\".*\" {if(!COMMENT)printf("\n\t %s is a STRING",yytext);}
[0-9]+ {if(!COMMENT) printf("\n %s is a NUMBER ",yytext);}
\)(\:)? {if(!COMMENT)printf("\n\t");ECHO;printf("\n");}
\( ECHO;
= {if(!COMMENT)printf("\n\t %s is an ASSIGNMENT OPERATOR",yytext);}
\<= |
\>= |
\< |
== |
\> {if(!COMMENT) printf("\n\t%s is a RELATIONAL OPERATOR",yytext);}
%%
int main(int argc, char **argv)
{
FILE *file;
file=fopen("var.c","r");
if(!file)
{
printf("could not open the file");
exit(0);
}
yyin=file;
yylex();
printf("\n");
return(0);
}
int yywrap()
{
return(1);
}
JXsKaW50IENPTU1FTlQ9MDsKJX0KaWRlbnRpZmllciBbYS16QS1aXVthLXpBLVowLTldKgolJQojLioge3ByaW50ZigiXG4lcyBpcyBhIHByZXByb2Nlc3NvciBkaXJlY3RpdmUiLHl5dGV4dCk7fQppbnQgfApmbG9hdCB8CmNoYXIgfApkb3VibGUgfAp3aGlsZSB8CmZvciB8CnN0cnVjdCB8CnR5cGVkZWYgfApkbyB8CmlmIHwKYnJlYWsgfApjb250aW51ZSB8CnZvaWQgfApzd2l0Y2ggfApyZXR1cm4gfAplbHNlIHwKZ290byB7cHJpbnRmKCJcblx0JXMgaXMgYSBrZXl3b3JkIix5eXRleHQpO30KIi8qIiB7Q09NTUVO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