我在C ++ bur上使用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;
我的野牛。
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();
}
我不知道这是否是我看不到的问题......
干杯,
答案 0 :(得分:1)
#define YYSTYPE Node*
我认为此行会导致问题,如果您最好使用%union
来自定义节点类型,例如
{% ... %}
%union {
Node* node_type;
}
%type <node_type> ast_root
%type <node_type> something0
%type <node_type> something1
%%
ast_root: ....