Creating leaves from terminal symbols
Leaves make up a large percentage of the nodes in a syntax tree. The leaves in a syntax tree built by yacc come from the lexical analyzer. For this reason, this section discusses modifications to the code from Chapter 2, Programming Language Design. After you create leaves in the lexical analyzer, the parsing algorithm must pick them up somehow and plug them into the tree that it builds. This section describes that process in detail. First, you will learn how to embed token structures into tree leaves, and you will then learn how these leaves are picked up by the parser in its value stack. For Java, you will need to know about an extra type that is needed to work with the value stack. Lastly, the section provides some guidance as to which leaves are necessary and which can be safely omitted. Here is how to create leaves containing token information.
Wrapping tokens in leaves
The tree
type presented earlier contains a field that is a reference...