A Parade of Errors
The best way to describe ANTLRâs error recovery strategy is to watch an ANTLR-generated parser respond to erroneous input. Letâs look at a grammar for a simple Java-like language containing class definitions with field and method members. The methods have simple statements and expressions. Weâll use it as the core of the examples in this section and the remainder of the chapter.
â | âgrammarâ Simpleâ;â |
â | |
â | progâ:â classDefâ+â â;â â// match one or more class definitionsâ |
â | |
â | classDef |
â | â:â â'class'â ID â'{'â memberâ+â â'}'â â// a class has one or more membersâ |
â | â{âSystemâ.âoutâ.âprintlnâ(ââ"class "ââ+$âIDâ.âtextâ ... |
Get The Definitive ANTLR 4 Reference, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.