Quote:
ANTLR’s error recovery mechanism is based upon Niklaus Wirth’s early
ideas in Algorithms + Data Structures = Programs 1 (as well as
Rodney Topor’s A Note on Error Recovery in Recursive Descent Parsers
2) but also includes Josef Grosch’s good ideas from his CoCo
parser generator (Efficient and Comfortable Error Recovery in Recur-
sive Descent Parsers 3). Essentially, recognizers perform single-
symbol insertion and deletion upon mismatched symbol errors (as
described in a moment) if possible. If not, recognizers gobble up sym-
bols until the lookahead is a member of the resynchronization set and
then exit the rule. The resynchronization set is the set of input symbols
that can legally follow references to the current rule and references to
any invoking rules up the call chain. Similarly, if the recognizer cannot
choose any of the alternatives from the start of a rule, the recognizer
again uses the gobble-and-exit strategy.
[...]
-- Terence Parr. The Definitive ANTLR Reference, 10.7 Automatic Error Recovery Strategy.
References
1 Niklaus Wirth. Algorithms + Data Structures = Programs. Prentice Hall PTR, Upper Saddle River, NJ, USA, 1978.
2 Rodney W. Topor. A note on error recovery in recursive descent parsers. SIGPLAN Not., 17(2):37–40, 1982.
3 Josef Grosch. Efficient and comfortable error recovery in recursive descent parsers. Structured Programming, 11(3):129–140, 1990.