More you share, more you have!!!

More you share, more you have!!!

LEX program to count the numbers of comment lines in a given C program

lex-program-c-file

Q.Write a LEX  program to count the numbers of comment lines in a given C program. Also eliminate them and copy the resulting program into separate file.

Source code:->

%{

int com=0;

%}

%%

"/*"[^\n]+"*/" {com++;fprintf(yyout, " ");}

%%

int main()

{

printf("Write a C program\n");

yyout=fopen("output", "w");

yylex();

printf("Comment=%d\n",com);

return 0;

}


Ouput:->

$lex p1b.l

$cc lex.yy.c –ll

$./a.out

       Write a C program

                     #include<stdio.h>

                       int main()

                        {

                         int a, b;

                           /*float c;*/

                          printf(“Hai”);

                          /*printf(“Hello”);*/

                            }

[Ctrl-d]

Comment=2

$cat output

#include<stdio.h>

int main()

{

    int a, b;

    printf(“Hai”);

}


Share on Google Plus
    Blogger Comment
    Facebook Comment

3 comments:


  1. Opti Farms Keto supports healthy immunity and drives to reduce overweight size
    of the body by eliminating bad cholesterol level. It improves ketosis that restricts
    fat accumulation inside the body and makes best utilized as energy boost. The supplement
    is one of the best selling product over the internet that makes you slim and stylish
    Opti Farms Keto

    ReplyDelete
  2. Hello, I am Prithvika malhotra thank you for this informative post. That is a great job. Wish you more success.Thank you so much and for you all the best. Takes Down
    https://thiscruelwar.tech

    ReplyDelete
  3. Hellio It is a great job, I love your posts and wish you all the very best. And I hope you continue doing this job well.
    Resurge

    ReplyDelete