Expected list of tokens provided by %errordefaulthandler explist
only lists shift tokens of most recent state
#265
Labels
%errordefaulthandler explist
only lists shift tokens of most recent state
#265
Here's a reproducer exhibiting two issues:
Note that it tests an input
11
which leads to a syntax error after the first1
and checks whether both;
and+
were listed as expected tokens.But if you compile and run it,
You can see that it only suggests
;
. That is due to two separate issues:happy
replaces erroring default actions with the most common reduction (seegetDefault
). After we shift the first1
and detect the error, we end up default-reducing all the way back up toStmts -> Stmts . ';' Stmt
, which neglects the itemExp -> Exp . '+' Exp
.getDefault
was "fixed", we'd be stuck in the reduction stateExp -> 1 .
, where there is no expected shift token whatsoever. That points out another flaw: The implementation of%errorhandlertype explist
is insufficient, because it only reports the tokens to be shifted for the topmost state on the stack. This strategy isn't so bad, but we'd better walk the whole state stack as if we successfully reduced and collect all shiftable tokens we encounter on the way (so it's rather not simply "walking the stack" I'm afraid). It ought to be possible to simulate this to get quite context-sensitive expected token lists. The next best solution would be to consider the set of tokens of the topmost state with a shift or a reduce action.Of course, (2) is infeasible for non-array-based parsers, or at least would require quite a bit of extra code.
The text was updated successfully, but these errors were encountered: