I am trying to learn Bison and flex. I am trying to build a simple command line calculator simular to the TI series of calculators.
When i put #define YYSTYPE double in the c declarations section of my exp.y file it appears to be ignored. here is a block of the relevent c code it generates #define YYSTYPE double #include <stdlib.h> ... #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) typedef int YYSTYPE; # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_TRIVIAL 1 #endif I am generating a header for the lex.yy.c file. It is NOT including the #define but does have the "int" block above. If I try to manually put the #define in the .h file then the compiler warns (and it still being defined as an int). The only way i can make it work is to remove the #define and change the typedef to double. a hack which is a PITA. I tried to compile the example reverse polish notation calculator with the same results. Everything is getting cast into integers. I am using version 1.875d of Bison , flex 2.5.31 and gcc (GCC) 3.3.5 (Debian 1:3.3.5-13) everything is as up to date as I can get from the stable repositories. here is snippets of the files where the problem might be. exp.y: %{ #define YYSTYPE double #include <stdlib.h> %} scan.lex: %option noyywrap %{ #include "exp.tab.h" %} %% [0123456789]+|([0-9]+[.][0-9]+) { yylval = atof(yytext); printf("%d,",yylval); printf("%f\n", yylval); return(NUMBER); } hmm .. think i fixed it. I saw it when i pasted the scanner. Ahh well i finish the post for others reference. I need to put the #define YYSTYPE double at the top of scan.lex file also BEFORE the include so it looks like the following: %option noyywrap %{ #define YYSTYPE double #include "exp.tab.h" %} %% [0123456789]+|([0-9]+[.][0-9]+) { yylval = atof(yytext); printf("%d,",yylval); printf("%f\n", yylval); return(NUMBER); } PS (please ignore all debugging statement and regex inefficencies. i fix those later :) -- View this message in context: http://www.nabble.com/YYSTYPE-doesnt-work-tf2297066.html#a6382028 Sent from the Gnu - Bison - Help mailing list archive at Nabble.com. _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison