I am implementing a parser of which the scanner (implemented using Flex) is not recognizing all the tokens at a time. It is just taking the first token from the input and terminating. Can someone please help me sort out this. Here is my ".lex" file:
%{
/* need this for the call to atof() below */
#include <math.h>
#include<string.h>
#include "parser.h"
#include "idf.tab.h"
char findname ( char *yytext) { return yytext[0]; }
%}
DIGIT [0-9]
ID [a-zA-Z]*
%option noyywrap
%%
{ID} |
-?{DIGIT}+"."{DIGIT}* |
-?{DIGIT}+ { printf("ID or number:%s\n",yytext); /*yylval.a_variable = (char*)findname(yytext);*/ return TOKID;}
";" { printf("Semicolon\n"); return TOKSEMICOLON; }
":" { printf("Colon\n"); return TOKCOLON;}
"," return TOKCOMMA;
"." return TOKDOT;
"-" return TOKMINUS;
[ \t\n] /* eat up whitespace */
. return TOKUNRECOG;
%%
int main( int argc,char* argv[] )
{
++argv, --argc;
if ( argc > 0 )
yyin = fopen( argv[0], "r" );
else
yyin = stdin;
yylex();
}
For example, if I give the input as abc;
the expected output should be:
ID or number: abc
Semicolon
But the actual output is:
ID or number: abc
That is, it is just recognizing the first token abc and terminating without recognizing the semicolon. Whereas if the input is just ;
then the output is
Semicolon