help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re[2]: Empty rule spoiling error reporting


From: Hans Aberg
Subject: Re[2]: Empty rule spoiling error reporting
Date: Tue, 10 Aug 2004 19:47:44 +0200

At 02:33 +0400 2004/08/10, hz kto wrote:
>I found a relatively well working solution to this without the grammar
>rewrite.
>During a reduction I check in yyr2[] whether the rule is empty, and if it
>is, I increment a counter.
>Counter gets reset on a non-empty reduction, after error, and on a
>successful shift.
>When an error happens I check for possible tokens, then see if my counter
>is >0. If it is, then look at the previous state on the stack, check for
>possible tokens again and add them to ones that I already found. Keep
>moving back and checking until counter is back to zero.
>
>This way I might find few tokens twice, but it is easy to ignore the
>duplicates.
>So far I haven't found any caveats with this method, if you see any,
>please let me know.

The set of valid token should probably be the set of all valid tokens you
find in those states, minus the set of all error tokens you find in those
states, as the parsing algorithm compactions works by labelling some error
tokens as valid, until a shift occurs.

If you do not want to set this counter by hand in each rule, you may modify
the Bison skeleton file: Right before the "switch" statement, which will
perform the reduction, check for the rule length, and alter the counter
accordingly.

Paul: I think this might be entered onto the Bison Todo list, in the
category of better error handling, which I think is on the future Bison
agenda.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]