January 2013
Intermediate to advanced
328 pages
8h 5m
English
In Chapter 10, Attributes and Actions, we learned how to embed actions within grammars and looked at the most common token and rule attributes. This section summarizes the important syntax and semantics from that chapter and provides a complete list of all available attributes.
Actions are blocks of text written in the target language and enclosed in curly braces. The recognizer triggers them according to their locations within the grammar. For example, the following rule emits found a decl after the parser has seen a valid declaration:
| | decl: type ID ';' {System.out.println("found a decl");} ; |
| | type: 'int' | 'float' ; |
Most often, actions access the attributes of tokens and rule references. ...
Read now
Unlock full access