On Sat, Feb 19, 2011 at 12:26:47PM -0500, Joel E. Denny wrote: > On Sat, 12 Feb 2011, Bill Allombert wrote: > > > I have a grammar that handles errors. > > Do you mean you're using Bison's error token?
Yes. > Or do you mean that you've written grammar rules that match syntactically > incorrect input? More or less. The grammar specification has a notion of the 'largest valid subexpression'. I use the error token to implement that: the error token mark the end of the expression. At this point I call yyerrok and continue. This works fine unless one of the largest valid subexpression is empty because bison will discard token instead fo reporting a syntax error. Basically I do: list: expr | list error {if (!once) { yyerrok; } once=1;} expr {once=0;} ; the variable once preventing two error to coalesce into one. > > However, in this contest, discarding > > tokens is highly undesirable, much more so than aborting. > > Do you mean that you've declared destructors with %destructor? No. However Chris verBurg suggested to me to add a destructor %destructor { ++number_discarded_symbols; } and to check at the end of parsing if number_discarded_symbols > 1 in which case the program abort with a syntax error. So far this has been successful. Cheers, Bill. _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison