A Lex Program to Count Number of Identifiers in a C program.
Note: Only type : int/float/double/char are supported.
Program:
%option noyywrap %{ int id_cnt=0; char ch; %} %% "int"|"float"|"double"|"char" { ch=input(); for(;;) { if(ch==',') id_cnt++; else if(ch==';') break; ch=input(); } id_cnt++; } %% main(int argc,char **argv) { FILE *fp; fp=fopen(argv[1],"r"); yyin=fp; yylex(); printf("\n total number of identifiers are %d",id_cnt); }
Comments
Post a Comment