bison c++:在 ‘*’ 之前预期初始化程序错误代币

发布于 2024-11-02 15:20:34 字数 748 浏览 3 评论 0原文

我在 C++ 上使用 flex 和 bison,但现在我很挣扎。

g++ 抛出的错误是:

src/bison.tab.h:125: error: expected initializer before ‘*’ token

bison.tab.h 是 bison yacc 解析器自动生成的文件,给我错误的行是

bison.tab.h:125: extern YYSTYPE yylval; 

My bison.y

void yyerror(const char* error);    
#include "objects/tabla.h"    
#include "Node.h"    
#define YYSTYPE Node*    
#include "bison.tab.h"    
#include "lex.yy.c"
using namespace std;       
void yyerror(const char* error) {cout<<"*** "<<error<<endl; };        
Node* root;    
%}    
%nonassoc vacio
%tokens 
%start start    
%%
Grammar....
%%
main()
{   
    yyparse();
}

我不知道这是否是我看不到的问题...

干杯,

I'm using flex and bison on C++ bur now I struggled.

The error that g++ throws is:

src/bison.tab.h:125: error: expected initializer before ‘*’ token

bison.tab.h is an auto generated file from bison yacc parser, the line that give me the error is

bison.tab.h:125: extern YYSTYPE yylval; 

My bison.y

void yyerror(const char* error);    
#include "objects/tabla.h"    
#include "Node.h"    
#define YYSTYPE Node*    
#include "bison.tab.h"    
#include "lex.yy.c"
using namespace std;       
void yyerror(const char* error) {cout<<"*** "<<error<<endl; };        
Node* root;    
%}    
%nonassoc vacio
%tokens 
%start start    
%%
Grammar....
%%
main()
{   
    yyparse();
}

I don't know if here is the problem that i can't see...

Cheers,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ㄟ。诗瑗 2024-11-09 15:20:34

#define YYSTYPE Node*

我认为这一行会导致问题,如果你最好使用 %union 来自定义节点类型,例如

{% ... %}

%union {
    Node* node_type;
}

%type <node_type> ast_root
%type <node_type> something0
%type <node_type> something1

%%

ast_root: ....

#define YYSTYPE Node*

I think this line leads to the problem, and if you'd better use %union to customize node type, like

{% ... %}

%union {
    Node* node_type;
}

%type <node_type> ast_root
%type <node_type> something0
%type <node_type> something1

%%

ast_root: ....
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文