January 2013
Intermediate to advanced
328 pages
8h 5m
English
ANTLR examines any left-recursive rule looking for one of four subexpression operator patterns.
Any alternative of the form expr op expr or expr (op1|op2|...|opN) expr. op can be a single-token or multitoken operator. For example, a Java grammar might treat angle brackets individually instead of treating operators <=> and >= as single tokens. Here’s an alternative that handles comparison operators at the same precedence level:
| | expr: ... |
| | | expr ('<' '=' | '>' '=' | '>' | '<') expr |
| | ... |
| | ; |
op can also be a rule reference. For example, we can factor out those tokens into another rule.
| | expr: ... |
| | | expr compareOps expr |
| | ... |
| | ; |
| | compareOps |
Read now
Unlock full access