Enter your email address & Win:

System Software Lab Programs ( Lex and Yaac Programs )1b

// June 8th, 2009 // Educational, Engineering, Unix and System Software Lab // Written by sandeephegde

-->

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:

  1. System Software Lab Programs ( Lex and Yaac Programs ) 3.l
  2. System Software Lab Programs ( Lex and Yaac Programs )exa
  3. System Software Lab Programs ( Lex and Yaac Programs ) 5b
  4. System Software Lab Programs ( Lex and Yaac Programs ) 5a
  5. System Software Lab Programs ( Lex and Yaac Programs ) 4a
  • Shashank
    This Answer doesn't solve eliminating the comments!!!!
  • sandeephegde
    Dear Shashank,

    I have not eliminated any comments from the site. Which eliminated comments are you talking about?
  • Shashank
    Hey Sandeep, I'm talking about the question which says that we need to eliminate the comments also along with counting no. of comments...Que goes like this:
    Program to count the numbers of comment lines in a given C program. Also ELIMINATE them and COPY THE RESULTING PROG INTO SEPARATE FILE. Ur prog just counts the comments, the rest of the que is left unsolved...
blog comments powered by Disqus
Get Adobe Flash playerPlugin by wpburn.com wordpress themes