簡體   English   中英

';'之前的預期類型說明符 Yacc中的令牌

[英]Expected type-specifier before ';' token in 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 ++中的保留字,並且會導致您提供的錯誤消息。

"Expected type-specifier before ';' token" "Expected type-specifier before ';' token"不是在gcc中產生的簡單錯誤: operator這種特殊用法是我所知道的少數情況之一。

問題與yacc從.y文件中放置%{ ... %}代碼的位置有關。 它包含在.tab.c文件中,但不包含在.tab.h文件中。 因此,如果你有任何其他代碼#include "y.tab.h" ,它需要#include "RA.h" ,否則你會因為RAoperator沒有被定義而得到這樣的錯誤(還)

使用bison,您可以使用%code requires { .tab.h %code requires { ... }來指定要復制到.tab.c.tab.h文件中的C代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM