if ='('current_tree insert_left(''p_stack push(current_treecurrent_tree current_tree get_left_child(elif not in ['+''-''*''/'')']current_tree set_root_val(int( )parent p_stack pop(current_tree parent elif in ['+''-''*''/']current_tree set_root_val(icurrent_tree insert_right(''p_stack push(current_treecurrent_tree current_tree get_right_child(elif =')'current_tree p_stack pop(elseraise valueerror return e_tree pt build_parse_tree(" )"pt postorder(#defined and explained in the next section the four rules for building parse tree are coded as the first four clauses of the if statement on lines and in each case you can see that the code implements the ruleas described abovewith few calls to the binarytree or stack methods the only error checking we do in this function is in the else clause where we raise valueerror exception if we get token from the list that we do not recognize now that we have built parse treewhat can we do with itas first examplewe will write function to evaluate the parse treereturning the numerical result to write this functionwe will make use of the hierarchical nature of the tree look back at figure recall that we can replace the original tree with the simplified tree shown in figure this suggests that we can write an algorithm that evaluates parse tree by recursively evaluating each subtree as we have done with past recursive algorithmswe will begin the design for the recursive evaluation function by identifying the base case natural base case for recursive algorithms that operate on trees is to check for leaf node in parse treethe leaf nodes will always be operands since numerical objects like integers and floating points require no further interpretationthe evaluate function can simply return the value stored in the leaf node the recursive step that moves the function toward the base case is to call evaluate on both the left and the right children of the current node the recursive call effectively moves us down the treetoward leaf node to put the results of the two recursive calls togetherwe can simply apply the operator stored in the parent node to the results returned from evaluating both children in the example from figure we see that the two children of the root evaluate to themselvesnamely and applying the multiplication operator gives us final result of the code for recursive evaluate function is shown below firstwe obtain references to the left and the right children of the current node if both the left and right children evaluate to nonethen we know that the current node is really leaf node this check is on line if trees and tree algorithms