Reputation: 12513
This seems to be a theoretical question.
As I far as I know ANTLR3 handles errors itself using its recover(###) method. I want to know what the method ANTLR3 uses for error recovery. (i.e. panic-mode/phrase-level etc.) Can someone help me figure this out?
It would be nice if someone can show me the declaration of its recover method, if my first guess is correct. Thank you.
Upvotes: 1
Views: 493
Reputation: 170288
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.
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.
Upvotes: 3