On Sun, 9 Oct 2011, David Kastrup wrote: > digging around on the web, I found an example of a failing YYBACKUP test > case in <URL:http://old.nabble.com/-PATCH--Update-TODO.-p20418035.html> > which has made it into the Bison TODO. Further digging revealed > <URL:http://www.mail-archive.com/[email protected]/msg03249.html>. > > Combining the information from both, the problem definitely appears to > be that YYBACKUP currently (as of bison 2.4.1, the version coming with > Ubuntu 11.10) does not correctly revert the state after popping the > stack.
For the record, this test case has been failing since at least bison 1.875, the oldest version I happen to have lying around. 1.875 was released in 2003, so this is a very old bug for which I don't recall many complaints. It seems YYBACKUP isn't used much. > So I can report just my findings: The following changed macro does > appear to do the trick: > As compared to the version in the default skeleton, there are two > changes. The first is an obvious enhancement: the "if" does not check > yylen, but YYPOPSTACK takes its argument from it. That way, rules > reducing more than one token can also be backed up. I'm a bit hesitant to extend the functionality of a feature that gets used so little. Back when I was learning bison originally, I had read that YYBACKUP was a confusing feature that was best avoided. I've never found motivation to use it. Can you explain a bit why you want it? > The actual bug fix is the addition of the line yystate = *yyssp which > makes the proposed example from the TODO (which is still there in > current master) actually work. Given that YYBACKUP is documented in the manual, I have no objections to adding the yystate fix, which makes sense to me and does fix the test case from TODO. I'll write a patch after this discussion. > It is a pity that I won't be able to use YYBACKUP for my current project > (Lilypond), but it seems worthwhile to have it fixed eventually. Well, if you're desperate, you could always define your own macro in your grammar file. Of course, that requires using internal features of the generated code, so there would be no guarantee of compatibility with future versions of bison. > I have not checked that the enhancement for reducing rules with more > than one token does actually work. It seems like an obvious change, but > I don't really understand Bison enough to be sure. Does this mean you haven't found need for that enhancement then? On Mon, 10 Oct 2011, David Kastrup wrote: > Adding yylen=0; after this line appears to be prudent as well, looking > at the rest of the code. At first glance, I don't see the need, but I guess it can't hurt. Do you have an example where it matters?
