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: ....
精彩评论