c++ - Yacc 中 ';' token 之前的预期类型说明符

标签 c++ bison yacc

我正在使用 yacc 解析一个文件并使用 yacc 将记录存储在 RAOperator 类对象中。 我在 yacc 文件中包含了相应的头文件,并在 yacc 文件的 %union 指令中定义了指向 RAOperator 对象的指针。但是编译的时候报错 如下:

exp.y:12:28: error: expected type-specifier before ‘;’ token

我附上了 yacc 文件,其中 union 与 RAoperator 类一起使用。

%{

#include "RA.h"
#include"y.tab.h"

%}

%union
{
char *strng;
vector<string>  *atr;
RAoperator* asdf;              // This is where error is shown
vector < vector <string> > *table;
}

这是 RA.h 文件,其中定义了 RAoperator。

class RAoperator
{
public:
vector< vector<string> > RArelation;
vector< vector<string> > RAattr;
};

我在 RA.h 文件中包含了所有必需的头文件。

我已经为这个错误搜索了很多,但找不到任何解决方案。

我哪里错了?

最佳答案

在指示错误的行中,它是否可能实际上说:

RAoperator* operator;

而不是 asdf? (包括您有 #define asdf operator 或等效项的情况)。 asdf 似乎是一个奇怪的标签名称; operator 会更符合逻辑,但它是 C++ 中的保留字,会导致您提供的错误消息。

“';' 之前的预期类型说明符token" 在 gcc 中不是一个容易产生的错误:operator 的这种特殊用法是我所知道的少数情况之一。

关于c++ - Yacc 中 ';' token 之前的预期类型说明符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18747424/

相关文章:

c++ - 当类包含在另一个类中时,为什么不转发类工作的声明

c++ - 带有嵌套 namespace 的 Bison 和 C++ 不会为我编译

parsing - Bison 语法文件中出现一次或多次

c - 如何解决在 Bison 中使用相同字符的两个不同运算符之间的歧义冲突

c - ANSI C YACC 语法中的歧义

bison - 使用可选分号转移/减少语法冲突

c++ - 如何使用 boost random 生成随机 64 位整数

c++ - g++ 不显示 'unused' 警告

c++ - 对 `yylex' 的 undefined reference && 对 `yyin' 的 undefined reference

c++ - 按值返回时不调用应对构造函数