1
Vote

Error Recovery with EOF

description

Hi,

I found a little improvement that can be made on ShiftReduceParserCode.cs.
When productions contains cascade error tokens only the most inner error is managed but then the parsing is interrupted causing an incomplete syntax tree.
This happens when I try to manage the closing errors of a block and blocks can be nested.
For example (c#):
class c {
    function f {
On DiscardInvalidTokens method:
if (NextToken == endOfFileToken)
    return false;
if (FsaState.ParserTable.ContainsKey(NextToken))
    action = FsaState.ParserTable[NextToken];
It can be check if NextToken is contained in FsaState.ParserTable before checking if NextToken is EOF.
if (FsaState.ParserTable.ContainsKey(NextToken))
    action = FsaState.ParserTable[NextToken];
else if (NextToken == endOfFileToken)
    return false;
This improve error recovery producing a more complete syntax tree.

comments