Exploring Parse Trees with the PyTree GUI
But wait—there is a better way to explore parse tree structures. Figure 19-1 shows the
parse tree generated for the string 1 + 3 (2 3 + 4), displayed in PyTree, the tree
visualization GUI described at the end of Chapter 18. This works only because the
parser2 module builds the parse tree explicitly (parser1 evaluates during a parse in-
stead) and because PyTree’s code is generic and reusable.
Figure 19-1. PyTree view of parse tree built for 1 + 3 (2 3 + 4)
If you read the last chapter, you’ll recall that PyTree can draw most any tree data struc-
ture, but it is preconfigured to handle binary search trees and the expression parse trees
we’re studying in this chapter. For parse trees, clicking on nodes in a displayed parse
tree evaluates the subtree rooted there.
1456 | Chapter 19: Text and Language