Lex Program to Identify the Type of Number [Compiler]

This is the lex program to identify the type of number using regular expressions
[cc lang=”c”]
%{
#include
int a=0,b=0,c=0,d=0;
%}
%%
[+]?[0-9]+ {printf(“Postive Integer %d”,a);a++;}
[-]{1}[0-9]+ {printf(“Negative Integer %d”,b);b++;}
[+]?[0-9]+[.]{1}[0-9]+ {printf(“Postive Fraction %d”,c);c++;}
[-]?[0-9]+[.]{1}[0-9]+ {printf(“Negative Fraction %d”,d);d++;}
%%
main(){yylex();}
[/cc]

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *