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
_______________________________________________ Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison