System Software Lab Programs ( Lex and Yaac Programs )1b
// June 8th, 2009 // Educational, Engineering, Unix and System Software Lab
Subject : System Software Laboratory
Branch : Information Science & Engineering
Semester : 6
University : VTU
………………………………………………………………………………………………………………………….
PART – A
………………………………………………………………………………………………………………………….
1b. Program to count the numbers of comment lines in a given C program. Also eliminate them and copy the resulting program into separate file.
%{
int c=0,state=1;
%}
%%
“/*” { state=0;}
“*/” { c++; if (!state) state=1;}
{ if (state==1)
fprintf(yyout,”%s”,yytext);
}
%%
FILE * fp;
main(int argc,char ** argv)
{
if(argc<=1)
{
printf(“\nNo file”);
exit(1);
}
fp=fopen(argv[1],”w”);
if(!fp)
{
printf(“\nNo output file”);
exit(1);
}
yyout=fp;
fp=fopen(argv[1],”r”);
if(!fp)
{
printf(“\nNo inpput file”);
exit(1);
}
yyin=fp;
yylex();
printf(“\nNumber of comment lines : %d”,c);
}
yywrap()
{
if(state==0)
{
printf(“\nUnterminated commennt”);
return 1;
}
}
If you enjoyed this post, make sure you subscribe to my RSS feed!
Related posts:
-
Shashank
-
sandeephegde
-
Shashank
Top Commentators
Abhijeet (1)
articlewritingtips (1)
Balachandra (1)
blaaze (1)
Flory (1)




