Sunday, 16 November 2014

LEX PROGRAM Program to count the no of comment lines



Program to count the no of comment lines from a given input c file and store the result in another file without those comment lines.


%{
#include<stdio.h>
int c=0;
%}
%%
[/][/][a-zA-Z0-9]* {c++;}
[/][*][a-zA-Z0-9][*][/] {c++;}
%%
main(int argc,char*argv[ ])
{
yyin=fopen(argv[1],"r");
yyout=fopen(argv[2],"w");
yylex();
printf("no of clines %d\n",c);
}

 

1 comment:

  1. %{
    #include
    int c=0;
    %}
    %%
    [/][/][a-zA-Z0-9]* {c++;}
    [/][*][a-zA-Z0-9][*][/] {c++;}
    %%
    main(int argc,char*argv[ ])
    {
    yyin=fopen(argv[1],"r");
    yyout=fopen(argv[2],"w");
    yylex();
    printf("no of clines %d\n",c);
    }

    ReplyDelete

Total Pageviews