I wrote bison code header:
%{
#include "foo.h"
%}
And I defined a struct named 'Foo' in header. I'd like to use it as token type in Bison.
%define api.value.type union
%token <Foo*> bar
Then I use -d
option to generate bison.tab.h
file.
bison -d bison.y
But there is no #include foo.h
in bison.tab.h
, and it use struct Foo to define the union YYSTYPE.
//bison.tab.h
union YYSTPE {
Foo* bar;
...
};
It caused error when compile this program: error: ‘Foo’ does not name a type
Is there a way to include header file in bison.tab.h
or another solution of this case?
%{
and%}
is not processed by Bison, it is copied straight into the generated C (or C++) source file. You can not put Bison-specific statements in a header file that way. – Ambulacrumfoo.h
andbison.y
. Because from what's currently given, this is how it's done. – Ballista