Write a LEX / FLEX program to Request input ,validate input and check for Even / Odd / Decimal | Compiler Construction

LEX / FLEX program to Request input ,validate input and check for Even / Odd / Decimal:-

Here is the LEX/FLEX Program which takes a number as input after that it will validate the input and check whether it is even or odd or decimal.

Source Code of  Lex Program:-


%{
#include<stdio.h> 
int count = 0; 
%} 

ODD -?[0-9]*[13579]
EVEN -?[0-9]*[02468]
DECI -?[0-9]*.[0-9]

%% 
END {return 0;}
{ODD} {printf("Given Number is Odd"); } 
{EVEN} {printf("Given Number is Even");}
{DECI} {printf("Given Number is Decimal");}
[A-Za-z0-9\.]* {printf("Invalid Input");}
%% 
  
int yywrap(){} 

int main()
       printf("Enter a Number\n");
       yylex();
       return 0;  
}


Output of above Lex Program:-



Must Read:-                      TCS CodeVita Question With Solution




Final Word:-

In this article, We have explained to you how to write a LEX / FLEX program to Request input ,validate input and check for Even / Odd / Decimal . 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.

                                        ( नमस्ते )

                                     🙏 



No comments:

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

Powered by Blogger.