Exercise 34. Analyzers
You now have a parser that should be producing a tree of grammar production objects. I’ll call this your “parse tree,” and it means you can analyze the whole program by starting at the top of the parse tree and then “walking” it until you’ve visited every node. You’ve done something like this when you were learning about the BSTree
and TSTree
data structures. You started at the top and visited each node, and the order you visited them in (depth-first, breadth-first, in-order, etc.) determined how the nodes were processed. Your parse tree has the same capability, and your next step in writing the little Python interpreter is to walk the tree and analyze it.
The analyzer’s job is to find semantic mistakes in your grammar ...
Get Learn More Python 3 the Hard Way: The Next Step for New Python Programmers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.