Sunday, 16 November 2014

LEX PROGRAM to recognize and count the no of identifiers in a given input file.



 program to recognize and count the no of identifiers in a given input file.

%{
#include<stdio.h>
int c=0;
char ch;
%}
%%
"int"|"float"|"double"|"long"|"short" {while(1)
{
ch=input();
if(ch==',')
c++;
else
if(ch==';')
c++;
break;
};}
. {;}
[\n] {;}
[a-z]+ {;}
%%
int main(int argc,char *argv[])
{
yyin=fopen(argv[1],"r");
yylex();
printf("count %d\n",c);
fclose(yyin);
}

 

No comments:

Post a Comment

Total Pageviews