[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
please help on infix yylex.
From: |
Laxman Bana |
Subject: |
please help on infix yylex. |
Date: |
Mon, 09 May 2005 04:09:24 +0000 |
Lex Gurus,
I am trying to learn flex and bison and I started with infix calc example
specified in the manual.
Everything is nomal when I use yylex() function specified in the manual. But
I wanted to generate tokens using flex and I created following rules and it
never worked....:(
I tried to fix this for long time but I am not able to see where I am making
a mistake? Please help.
Thanks,
Laxman
/* infix.l */
%{
#include <math.h>
#include <infix.tab.h>
extern int yylval;
%}
WS [ \t\n]
DIGIT [0-9]
%%
{DIGIT}+ { yylval = atoi(yytext); return NUM; }
{WS} ; /* eat empty spaces. */
. return yytext[0];
%%
yywrap()
{
return 1;
}
/* infix.y */
%{
#define YYSTYPE int
#include <math.h>
#include <stdio.h>
%}
%token NUM
%%
input:
| input line
;
line: '\n'
| exp '\n' { printf ("\t= %d\n", $1); }
;
exp: NUM { $$ = $1; }
| exp '+' exp { $$ = $1 + $3; }
| exp '-' exp { $$ = $1 - $3; }
| exp '*' exp { $$ = $1 * $3; }
| exp '/' exp { $$ = $1 / $3; }
;
%%
main()
{
yyparse();
}
yyerror(s)
char *s;
{
printf("%s \n", s);
}
commands:
$ flex -oinfix.l.c infix.l ; bison -d -oinfix.tab.c infix.y
$ gcc -I. -o infix infix.l.c infix.tab.c
flex version : 2.5.4
Bison version: 1.875b
- please help on infix yylex.,
Laxman Bana <=