野牛版本之间的差异

时间:2012-12-08 00:52:11

标签: bison

我是词法分析和解析器生成的新手,我试图直接从wikipedia编译野牛示例。这是一个可重入解析器的示例。

我尝试用2个版本的野牛编译:2.5和2.6.5。前者编译和执行完美,但后者包括解析器头中的类型yyscan_t,它在词法分析器头(Lexer.h)中声明(我猜这是重入特征所必需的)。因此,它不会编译由Parser.c

生成的Parser.y

以下是Parser.h中2.6.5生成的额外部分,其中不存在于2.5:

#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int yyparse (void *YYPARSE_PARAM);
#else
int yyparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int yyparse (SExpression **expression, yyscan_t scanner); // this line
#else
int yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */

我已标记导致问题的线条。有什么想法吗?

编辑:我需要做的是确保在bison生成的头文件中声明yyscan_t

1 个答案:

答案 0 :(得分:3)

实际上,自2.6以来的野牛在标题部分插入了前面提到的代码块。

你需要通过移动%code {...}(或%{...%})部分的子部分来告诉bison在此块之前插入yyparse函数参数的所有声明带有标记'requires'的新代码部分,以便在yy文件中插入标题的顶部:

%code requires {
typedef void*                 yyscan_t;
} 

参见野牛破碎手册:

http://www.gnu.org/software/bison/manual/html_node/_0025code-Summary.html

http://www.gnu.org/software/bison/manual/html_node/Prologue-Alternatives.html#Prologue-Alternatives

希望有所帮助