我写了野牛代码头:
%{
#include "foo.h"
%}
Run Code Online (Sandbox Code Playgroud)
我在标头中定义了一个名为“ Foo”的结构。我想将其用作Bison中的令牌类型。
%define api.value.type union
%token <Foo*> bar
Run Code Online (Sandbox Code Playgroud)
然后我使用-d选项来生成bison.tab.h文件。
bison -d bison.y
Run Code Online (Sandbox Code Playgroud)
但是#include foo.hin 中没有bison.tab.h,它使用结构Foo定义联合YYSTYPE。
//bison.tab.h
union YYSTPE {
Foo* bar;
...
};
Run Code Online (Sandbox Code Playgroud)
编译该程序时导致错误: error: ‘Foo’ does not name a type
有没有办法在bison.tab.h这种情况下包含头文件或其他解决方案?