%{ #include<stdio.h> int count=0; %} %% "/*"[^\n]+"*/" {count++;fprintf(yyout,"");} "//".* { count++; fprintf(yyout,"");} %% int main() { yyin=fopen("open.c","r"); yyout=fopen("new.c","w"); yylex(); printf("Number of Comments=%d\n",count); return 0; } download the program file How to run this file 1. run lex file using command " flex filename.l " 2. it generate the c file which can be execute by command " cc lex.yy.c -ll " 3. it will generate the executable file " ./a.out "