Chapter 10Attributes and Actions
So far, weâve isolated our application-specific code to parse-tree walkers, which means that our code has always executed after parsing is complete. As weâll see in the next few chapters, some language applications require executing application-specific code while parsing. To do that, we need the ability to inject code snippets, called actions, directly into the code ANTLR generates. Our first goal, then, is to learn how to embed actions in parsers and lexers and to figure out what we can put in those actions.
Keep in mind that, in general, itâs a good idea to avoid entangling grammars and application-specific code. Grammars without actions are easier to read, arenât tied to a particular target language, ...
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.