Write a program parse_tree.py
that uses the BinaryTree
and Stack
classes to create a binary tree from a fully-parenthesized expression. Do this by pushing the current tree (current_focus
) onto a stack when we descend to its subtree to edit that subtree), then pop the stack to get back to previous parent trees when done filling out the subtree.
Your program should include two functions:
build_parse_tree(expr)
which takes a fully-parenthesized expression as a string parameter and builds a binary parse tree from it, andevaluate(parse_tree)
which goes through and solves the problem as represented in the tree