Building a Language Application
Continuing with our array initializer example, our next goal is to translate not just recognize initializers. For example, let’s translate Java short arrays like {99 , 3 , 451 } to "\u0063\u0003\u01c3" where 63 is the hexadecimal representation of the 99 decimal.
To move beyond recognition, an application has to extract data from the parse tree. The easiest way to do that is to have ANTLR’s built-in parse-tree walker trigger a bunch of callbacks as it performs a depth-first walk. As we saw earlier, ANTLR automatically generates a listener infrastructure for us. These listeners are like the callbacks on GUI widgets (for example, a button would notify us upon a button press) or like SAX events in an XML parser. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access