On Mon, 21 Aug 2006, Paul Eggert wrote:
> "Joel E. Denny" <[EMAIL PROTECTED]> writes:
> > Can you give me an example of how error token values would be useful?
>
> Well, I dunno. Suppose you're parsing HTML and have as a semantic
> value a list of all the href= values in that subtree. And when you
> parse a busted subtree you still want its href= values.
So, the error token becomes a nonterminal and its RHS is the sequence of
discarded symbols?
Unfortunately, $n is static, and the RHS length and symbol types aren't
known until run time here.
Maybe the user could write this:
error:
/* empty */ { /* Init $$. */ }
| error sym1 { /* Append sym1 to $$. */ }
| error SYM2 { /* Append SYM2 to $$. */ }
| error <field1> { /* Automatic rules for syms of type <field1>. */ }
| error <field2> { /* Automatic rules for syms of type <field2>. */ }
| error %any { /* Default rule? */ }
;
Bison would not allow rules of any other form when the LHS is error. If
there's no rule for a particular symbol, the parser would discard that
symbol during error recovery.
(Hmm... I like %any. I wonder if I should use that for the default
%destructor/%printer notation instead of just an empty list.)
Joel