yacc 似乎不喜欢我的标记是我定义的类型。
在
.y
块中的语法 (%{ ... %}
) 文件的顶部,我包含一个定义以下结构的头文件:
typedef struct _spim_register {
spim_register_type type; /* This is a simple enumeration, already defined */
int number;
} spim_register;
在我的规则列表之前,我有:
%token AREG
...
%union {
struct _spim_register reg;
}
...
%type <reg> register AREG
我明白了
错误:字段“reg”的类型不完整
在
%union
子句中的行,同时尝试编译 bison 生成的代码。在我的 %union
声明中,尝试通过编写 spim_register reg;
来声明 reg 给出了错误:
unknown type name ‘spim_register’
%union { ... }
似乎有一些特别之处,因为我能够在规则的操作中使用头文件中的数据结构。
*.l
文件是这样的:
#include "y.tab.h"
#include "FP.h"
我改写成这样:
#include "FP.h"
#include "y.tab.h"
有效。