简体   繁体   中英

bison c++: 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 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: ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM