开发者

bison c++: error expected initializer before ‘*’ token

开发者 https://www.devze.com 2023-02-27 06:32 出处:网络
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

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开发者_Python百科 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,


#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: ....
0

精彩评论

暂无评论...
验证码 换一张
取 消