yacc - 字段类型不完整

问题描述 投票:0回答:2

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 { ... }
似乎有一些特别之处,因为我能够在规则的操作中使用头文件中的数据结构。

c bison yacc
2个回答
11
投票

如果我的

#includes
顺序正确,那将会有所帮助...

答案是,正如 user786653 暗示的那样,here。我需要包含定义我的自定义结构的头文件before包括

.tab.h
文件在
.l
文件中


8
投票
我遇到了同样的问题。因为我的

*.l

文件是这样的:

#include "y.tab.h" #include "FP.h"
我改写成这样:

#include "FP.h" #include "y.tab.h"
有效。

© www.soinside.com 2019 - 2024. All rights reserved.