【发布时间】:2020-07-11 17:47:52
【问题描述】:
我正在尝试制作一个可重入的 flex&bison 解析器,但出现了这个奇怪的错误:
too few arguments to function call, expected 5, have 4
我可以看到 Bison 生成的代码是这样的:
static void
yydestruct (const char *yymsg,
yysymbol_kind_t yykind, YYSTYPE *yyvaluep, void *scanner, struct BisonOutput *out)
{ ...some code... }
和
int
yyparse (void *scanner, struct BisonOutput *out)
{
...some code...
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval, out); // <--- here void*scanner parameter is clearly missing
...some code...
}
我的代码是这样的:
%define api.pure full
%lex-param {void *scanner}
%parse-param {void *scanner, struct BisonOutput *out}
%{
struct BisonOutput{
int out;
};
#include "syntax_parser.h"
#include "lex.yy.h"
#include <stdio.h>
%}
%define api.value.type union
%token <int> NUM
...bunch of other tokens...
%%
...bunch of grammar rules...
%%
... main function and such ...
而Flex代码如下:
%{
#include "syntax_parser.h"
%}
%option reentrant bison-bridge noyywrap
blanks [ \t\n]+
number [0-9]+
%option noyywrap
%%
... bunch of rules ...
我真的迷路了。为什么野牛不将scanner 插入yydestruct,尽管在yyparse 中明确使用它?
【问题讨论】:
-
syntax_parser.h和lex.yy.h是什么?
标签: c bison flex-lexer reentrancy