ADVERTISEMENT
ADVERTISEMENT

Home » Compiler Design

LEX Code to identify and print integer and float value in given Input pattern

In this article, we going to learn how to create LEX program to analysis whether a input number is integer number or decimal number?
Submitted by Ashish Varshney, on March 24, 2018

For achieve to this task we create some rules in rule section in the code.

Example:

    Input: 56
    Output: Integer number
    Input: 0.2
    Output: Decimal Number
/*Definition Section*/

%{
#include<stdio.h>
%}


/*Rule Section*/

%%

/*Check the token, if token is match with 
pattern then it will print Decimal Number.*/
[0-9]+"."[0-9]+ {ECHO; printf("\nDecimal Number\n");}  
/*Check the token, if token is match with 
pattern then it will print Integer Number.*/
[0-9]+ {ECHO; printf("\nInteger Number\n");}			

%%
/*call the yywrap function*/
int yywrap()		
{return 1;}


/*Auxiliary function*/
/*Driver function*/

int main(void)
{
/*call the yylex function.*/
yylex();
return 0;
}
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.