Implementing Applications with Parse-Tree Listeners
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: ...
Get The Definitive ANTLR 4 Reference, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.