Flex/Lex program to detect white-space, tab, single line comments, multiple line comment and Remove it | Tech With Code


Flex/Lex program to detect white-space, tab, single-line comments, multiple line comments, and Remove it:

                                                                                                    Today I will show you how to write a Lex/Flex program that detects white-space, tab, single-line comments, multiple line comments, and after that remove all of these and print that as an output.

Also Read:- LEX-FLEX-program-to-check-for-Even-Odd-Decimal


This is TechWithCode.com
Here    You will get all programming Source Code
//this is first single line  comment
//this is second single line  comment


No. of spaces=8
No. of tabs=1
No. of Single Line Comments=2

No. of Multiple Line Comments=1

After Removal:-




Source Code of Flex program:-

int slc=0, sc=0, tc=0, flag =0, mlc=0;

" " {sc++;} //space counter 
\t {tc++;} //tab counter 
"//".*\n {slc++;} //single line comment
"/*"[^*/]*"*/" {mlc++;} // multiple line comment

int yywrap(){return 1;}


printf("After Execution:-\n\n");
printf("\n\nIn the Input File,");
printf("\nNo. of spaces=%d",sc); 
printf("\nNo. of tabs=%d",tc); 
printf("\nNo. of Single Line Comments=%d",slc); 
printf("\nNo. of Multiple Line Comments=%d",mlc);


OutPut of Flex Program:-

Must Read:-                      TCS CodeVita Question With Solution

Final Word:-

In this article, We have explained to you how to write a Flex/Lex program to detect white-space, tab, single-line comments, multiple line comments, and Remove it. We hope you like it

If This post helps you a little bit then please share this post with your friends. For more Computer and programming Related Tips and tricks, please

Follow us on Facebook
Subscribe us on Youtube
Follow us on Instagram
Follow us on Pinterest
follow us on Telegram

Don't forget to share how you like this Content in the comment below. If you have any doubt or suggestion then please write in the comment section below, we will love to hear from you.

                               Thank you.

                                        ( नमस्ते )



  1. Hey There. I found your blog using Google. This is a very well written article. I’ll be sure to bookmark it and come back to read more of your useful info. Thanks for the post. I’ll definitely return.
    Regularly scheduled programming

  2. https://sites.google.com/site/ytviewsindiabuy/ Does this sound familiar? You're playing your favourite game, and getting pretty good at it too, then suddenly the screen goes blank and that fateful message appears "DISC READ ERROR". All of a sudden you get extremely frustrated really fast and all you can do is let out a scream...

  3. https://twitchviral.com/ There are many educational games for the Nintendo DS. From subject-specific games to all-in-one generalized teachers, from IQ-testing to barely-educational, Nintendo's catalog of educational DS games is a sprawling list. How does a parent make heads or tails of such a wide variety? How can a parent choose a learning game to fit a child's needs? Well, we're here to help.


Do not add any link in the comments.
For backlink, contact us.

Powered by Blogger.