Friday, May 3, 2019

SS 6.A - LEX - ELIMINATE COMMENT LINES IN A C PROGRAM

6 - a) Write a LEX program to eliminate comment lines in a C program and copy the resulting program into a separate file.

lab6.l - PROGRAM

%{
#include<stdio.h>
int sl=0;
int ml=0;
%}
%%
"/*"[a-zA-Z0-9' '\t\n]+"*/" ml++;
"//".* sl++;
%%

main()
{
yyin=fopen("f1.c","r");
yyout=fopen("f2.c","w");
yylex();
fclose(yyin);
fclose(yyout);
printf("\n Number of single line comments are = %d\n",sl);
 printf("\nNumber of multiline comments are =%d\n",ml);
}

f1.c FILE

#include<stido.h>

int main()
{
// this is a comment
printf("hello");
/* this is another comment */
}


OUTPUT :( click on image to zoom )



No comments:

Post a Comment