Skip to main content

No of comments lines in the c file and eliminate them and save into other file



%{
#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;
}



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 "


Comments

  1. Lucky Club: The Definitive Guide to the Best Betting Sites & Sites
    Betting luckyclub sites for the whole of Europe. A guide to the best betting sites and websites to make money. The betting odds at these sites

    ReplyDelete

Post a Comment

Popular posts from this blog

YACC Program to check whether the arithmetic expression is valid or not

validexp.l //LEX Program /* declaration section in this sections we will declare the different value and include the header file which we are using in this program to run this program */ %{ #include"y.tab.h" extern yylval; %} /* defined section */ %% [0-9]+ {yylval=atoi(yytext); return NUMBER;}    //this is send to the yacc code as token INTEGER [a-zA-Z]+ {return ID;}                                          //this is send to the yacc code as token  ID [\t]+ ; \n {return 0;} . {return yytext[0];} %%    validexp.y  //yacc program //decelration section %{ #include<stdio.h> %} //definition section %token NUMBER ID                        // token from lex file %left '+' '-'                    ...

YACC Program to evaluate the arithmetic expression and check validation and print the result

arithmetic.l //lex program /* declaration section in this sections we will decleared the different value and include the header file which we are using in this program to run this program */ %{ #include<stdio.h> #include "y.tab.h" extern int yylval; %} /* this sections is known as defined section in which we defined the rule and regulation of regular expression which will be going to accept or not */ %% [0-9]+ {           yylval=atoi(yytext);           return NUMBER;        } [\t] ; [\n] return 0; . return yytext[0]; %% int yywrap() { return 1; } arithmatic.y /* yacc program for soving arithmatic expression */ /* decleration section in this sections we will decleared the different  value and include the header file which we are using in this program to run this program */ %{     #include<stdio.h>     int flag=0;   ...

LEX to count the no of "scanf" and "printf" statement in a c program. Replace them with "writf" and "readf" respectively.

/* declaration section in this sections we will declare the different value and include the header file which we are using in this program to run this program */ %{ #include<stdio.h> int sf=0,pf=0; %} /* defined section */ %% "scanf" { sf++; fprintf(yyout,"readf");}            // replace scanf  with readf "printf" { pf++; fprintf(yyout,"writef");}            // replace printf  with writef %% int main() { yyin=fopen("open.c","r");                            // input file open.c yyout=fopen("new.c","w");                            // output file new.c with replace  yylex();      //no of printf and scanf in the file printf("Number of scanfs=%d\nNumber of Printf's=%d\n",sf,pf); return 0; } download the file  ...