Bison:yywrap() 再次完全解析同一个文件?

Bison: yywrap() to parse same file exactly one more time?

我有一些由数字组成的数据,我想在用 Flex 进行词法分析后用 Bison 进行解析。为此,我需要知道我所有数字的最小值和最大值 - 如果我作弊并明确定义这些,我可以做到。

我知道在我 运行 第一个解析器函数之前我必须最终自动找到所有行的最大值。

我想我会使用 yywrap() 但它并没有 return 一开始。

这是我的 yywrap():它 return 一次 0 然后 1,但似乎没有 return 到开始之间.它保留在最后,我的测试 printf(s) 并排出现在那里。-

int wrap;
int yywrap()
{
if (wrap == 0) {wrap++;return 0;}
else {return 1;}
}

目前
输入:

--
G0
G0
G0
e0
--
--
--
--
F0
F0
F0
D0
--
--
--

输出:

------------
67----------
67----------
67----------
--------63--
------------
------------
------------
------------
----65------
----65------
----65------
----------62
------------
------------
------------

flex manual 关于使用 yywrap 有这样的说法(强调已添加):

When the scanner receives an end-of-file indication from YY_INPUT, it then checks the yywrap() function. If yywrap() returns false (zero), then it is assumed that the function has gone ahead and set up yyin to point to another input file, and scanning continues. If it returns true (non-zero), then the scanner terminates, returning 0 to its caller. Note that in either case, the start condition remains unchanged; it does not revert to INITIAL.

所以如果你想 rewind(yyin),你需要自己在 yywrap 函数中这样做。