To build language applications without entangling the application and the grammar, the key is to have the parser create a parse tree and then walk it to trigger application-specific code. We can walk the tree using our favorite technique, or we can use one of the tree-walking mechanisms that ANTLR generates. In this section, we’re going to use ANTLR’s built-in ParseTreeWalker to build a listener-based version of the property file application from the previous section.
Let’s start with a denuded version of the property file grammar.
file : prop+ ;
prop : ID '=' STRING '\n' ;
Here’s a sample property file: