January 2013
Intermediate to advanced
328 pages
8h 5m
English
If you turn on the -Xlog ANTLR command-line option, you can find the transformed left-recursive rules in the log file. Here’s what happens to rules stat and expr from Expr.g4 shown earlier:
| | // use "antlr4 -Xlog Expr.g4" to see transformed rules |
| | stat: expr[0] ';' ; // match an expr whose operators have any precedence |
| | |
| | expr[int _p] // _p is expected minimum precedence level |
| | : ( INT // match primaries (non-operators) |
| | | ID |
| | ) |
| | // match operators as long as their precedence is at or higher than |
| | // expected minimum |
| | ( {4 >= $_p}? '*' expr[5] // * has precedence 4 |
| | | {3 >= $_p}? '+' expr[4] // + has precedence 3 |
| | )* |
| | ; |
Whoa! ...
Read now
Unlock full access