Mail Archives: djgpp/1997/04/16/12:10:08
Gurunandan R. Bhat wrote:
#define YYSTYPE double
>at the beginning of the bison source. on doing this and
>compiling with -d, bison generates a header file which is
>expected to contain all type information required by the
Not quite. Anything in the explicit source code between
%{ and %} is just passed straight through to the output,
without bison looking at it. So bison doesn't 'know' that
you've redefined YYSTYPE and doesn't generate the changed
definition in the header file it produces.
However, it does allow you to redefine the type. Look again
at the definition in the header file:
#ifndef YYSTYPE
#define YYSTYPE int
#endif
That means that if you define YYSTYPE before including the
header file it will use your definition instead of the
default 'int'. In general it's best to have a common
header file which is included by both the bison and the
flex source, so in the .y file would be:
%{
#include "common_defs.h"
...
%}
and in the .l would be:
%{
#include "common_defs.h"
#include "program_tab.h"
...
%}
(Or whatever the DOS bison produces as the .h file, I'm
on Unix at the moment and don't remember the DOS version
of the file name, it's file.tab.h under Unix.)
The file "common_defs.h" (oops, that's not a DOS filename
either but you know what I mean!) would contain:
#define YYSTYPE double
If it's not clear, drop me an email and I'll try to do
better...
Chris
- Raw text -