Floating Point & Integers Lex Program Compiler Design

Program:


// frn.l


%{

%}

DIGIT    [0-9]

%%

{DIGIT}*        {ECHO;printf(" Integer");}
{DIGIT}*?\.{DIGIT}*    {ECHO;printf(" Float ");}

%%
main()
{
    yylex();
}


Output:


nn@linuxmint ~ $ lex frn.l
nn@linuxmint ~ $ gcc lex.yy.c -ll
nn@linuxmint ~ $ ./a.out<test1.txt
1 Integer
500 Integer
10.1 Float
.1 Float
1.0 Float

nn@linuxmint ~ $

// input : test1.txt

1
500
10.1
.1
1.0

2 comments:

Related Posts Plugin for WordPress, Blogger...