07-05-2011, 12:53 PM
Objective
Program to count the number of identifiers in a c file
Program:
Code:
%{
#include<stdio.h>
int id=0, i;
%}
%%
"int " ||
"float " ||
"double " ||
"char " ||
"bool " {
i = 0;
while (yytext[i] != ';')
{
if(yytext[i] == ',')
id++;
i++;
}
id++;
}
. ;
%%
int main(int argc, char *argv[])
{ yyin = fopen(argv[1],"r");
yylex();
printf("No. of identifiers = %d\n",id);
}