January 2013
Intermediate to advanced
328 pages
8h 5m
English
To use a visitor instead of a listener, we ask ANTLR to generate a visitor interface, implement that interface, and then create a test rig that calls visit on the parse tree. We don’t have to touch the grammar at all.
When we use the -visitor option on the command line, ANTLR generates interface PropertyFileVisitor and class PropertyFileBaseVisitor, which has the following default implementations:
| | public class PropertyFileBaseVisitor<T> extends AbstractParseTreeVisitor<T> |
| | implements PropertyFileVisitor<T> |
| | { |
| | @Override public T visitFile(PropertyFileParser.FileContext ctx) { ... } |
| | @Override public T visitProp(PropertyFileParser.PropContext ctx) { ... } |
| | } |
We can copy the map functionality ...
Read now
Unlock full access