January 2013
Intermediate to advanced
328 pages
8h 5m
English
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);} |
| | ; |
| | |
| | member |
| | : 'int' ID ';' // field definition |
| | {System.out.println("var ... |
Read now
Unlock full access