错误:预期的说明符限定符列表位于“TR”之前
我在 Bison 上的联合内部定义结构时遇到问题,
我创建了一个结构
typedef enum {Binary_Op,Uni_Op,Variable, Const} Tag_Type;
typedef struct tree
{
Tag_Type Tag;
union
{
struct
{
char op;
struct tree *left, *right;
}bin_op;
struct
{
char op;
struct tree *arg; /* negative or positive */
}uni_op;
char var;
int const_val;
}u;
}TREE_REC, *TR;
%}
%union
{
int y_int;
TR y_tree;
}
%type <y_tree> expr term factor assign
%token <y_int> CONST
%token <y_int> VAR
%%
,但在联合 TR 内部有错误。我不明白为什么!!有什么帮助吗?
I have a problem defining my structure inside the union on Bison
I made a structure
typedef enum {Binary_Op,Uni_Op,Variable, Const} Tag_Type;
typedef struct tree
{
Tag_Type Tag;
union
{
struct
{
char op;
struct tree *left, *right;
}bin_op;
struct
{
char op;
struct tree *arg; /* negative or positive */
}uni_op;
char var;
int const_val;
}u;
}TREE_REC, *TR;
%}
%union
{
int y_int;
TR y_tree;
}
%type <y_tree> expr term factor assign
%token <y_int> CONST
%token <y_int> VAR
%%
but inside the union TR has an error. I don't understand why!! any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在
#include "y.tab.h 之前
。该错误消息告诉您,您正在尝试在编译器看到 TR 的定义之前使用它。#include
的头文件中定义struct tree
和TR
“You need to define
struct tree
andTR
in a header file that you#include
before you#include "y.tab.h"
. The error message is telling you that you're trying to useTR
before the compiler has seen a definition for it.我对你的 typedef struct tree {...} TREE_REC, *TR 有点困惑。我宁愿写:
你的 typedef 中的
,
令我不安。您可以测试我的解决方案,或者只是澄清您的 typedef 的语法吗?
I'm a bit confused with your
typedef struct tree {...} TREE_REC, *TR
. I would have rather written :The
,
in your typedef is disturbing me.Can you test my solution, or just clarify the syntax of your typedef?