c - yacc - 字段的类型不完整

标签 c bison yacc

当我的标记属于我定义的类型时,yacc 似乎不喜欢。

在我的语法 (.y) 文件顶部的 %{ ... %} block 中,我包含了一个定义以下结构的头文件:

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

我明白了

error: field ‘reg’ has incomplete type

在尝试编译由 bison 生成的代码时,在 %union 子句中的行。在我的 %union 语句中,尝试通过编写 spim_register reg; 来声明 reg 给出了错误:

unknown type name ‘spim_register’

似乎 %union { ... } 有一些特别之处,因为我能够在规则的操作中使用头文件中的数据结构。

最佳答案

如果我的 #includes 顺序正确,那将会有所帮助...

正如 user786653 所暗示的那样,答案是 here .我需要在 之前包含定义我的自定义结构的头文件,包括 .l 文件中的 .tab.h 文件。

关于c - yacc - 字段的类型不完整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7639922/

相关文章:

c - fprintf 字符串终止的心理障碍

c - 将 fnmatch 与 char 指针一起使用

C和 Bison : pointers to struct in %union definition

programming-languages - yacc/lex还是手动编码?

c++ - 当 main 在另一个文件中时出现编译错误(g++、bison、flex)

c - 随机生成的二维噪声

c - c中free函数的使用

c - 弹性/Bison : Error recovery destructors?

c++ - Bison 将 C 函数指针作为函数调用?

在语句结尾解析可选分号