I'm working on a parser in Bison. When parsing a test case, Bison gives a syntax error, saying that it expected $end,开发者_如何学C but there were more tokens. I've searched the Bison manual for $end, but it doesn't seem to indicate in what conditions exactly it will expect that token. I've used a recursive rule of the form
%start program
%%
program
: rule
| program rule;
to define my grammar's root. Bison happily matches the first three invocations of rule
but throws on the fourth one, saying that it expected $end. How can I indicate to Bison that it should expect and match more tokens?
Sounds like your problem is somewhere in the details. Something near the end of your input stream doesn't match "rule". Switch on debugging and see what that tells you (check out YYDEBUG and yydebug, if you're not familiar with them.)
Just to be clear: When you say "fourth invocation" I presume you mean "fourth independent test case" (and so the fact that it's the fourth is irrelevant.) Or do you mean that an input stream that matches "rule" four times fails but one that matches three times succeeds?
精彩评论