January 2013
Intermediate to advanced
328 pages
8h 5m
English
Listeners and visitors are great because they keep application-specific code out of grammars, making grammars easier to read and preventing them from getting entangled with a particular application. For the ultimate flexibility and control, however, we can directly embed code snippets (actions) within grammars. These actions are copied into the recursive-descent parser code ANTLR generates. In this section, we’ll implement a simple program that reads in rows of data and prints out the values found in a specific column. After that, we’ll see how to make special actions, called semantic predicates, dynamically turn parts of a grammar on and off.
We can compute values ...
Read now
Unlock full access