Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If we have a mapping from every location in the grammar to a position in an ATN, we should be able to do a pretty good job of their error recovery. For example, we can supply error alternatives without bloating the generated code at all. Here is a contrived example with two regular alternatives and two error alternatives:

...

If there's a syntax error, we can suspend the parser and launch an interpreter that tries to match one of your the error alternatives. If one succeeds, the an action in that alternative will properly report an error and resynchronize. If nothing matches, we can do the standard recovery boogie.

The standard error recovery is to compute the set of possible following symbols, based using the parsing stack as context to provide the exact follow rather than FOLLOW(the-rule). If we have the entire grammar represented in some way, ANTLR does not have to compute and then generate code to store bits sets for error recovery. I can just walk the ATN at runtime. It also doesn't have to pass these bits it's around as it does in v3. For rule reference r, currently I need to generate:

...