Forming syntax trees for the Jzero language
This section shows you how to build syntax trees for the Jzero language. The full j0gram.y
file for this chapter is available on the book’s GitHub site. The header is omitted here since the %token
declarations are unchanged from how they appeared in the section titled The Jzero Yacc specification in the previous chapter. Although we are again presenting many of the grammar rules shown in the last chapter, the focus now is on the construction of new tree nodes associated with each production rule, if any.
As described earlier, the tree’s internal nodes are constructed in semantic actions that are added at the ends of production rules. For each production rule that builds a new node, the new node is assigned to $$
, the yacc value stack entry that corresponds to the new non-terminal symbol built by that production rule.
The starting non-terminal, which in the case of Jzero is a single class declaration, is the point at...