class expressiontree(linkedbinarytree) """an arithmetic expression tree "" def init (selftokenleft=noneright=none) """create an expression tree in single parameter formtoken should be leaf value ( ) and the expression tree will have that value at an isolated node in three-parameter versiontoken should be an operator and left and right should be existing expressiontree instances that become the operands for the binary operator ""linkedbinarytree initialization superinit if not isinstance(tokenstr) raise typeerrortoken must be string use inheritednonpublic method self add root(token if left is not nonepresumably three-parameter form if token not in +-* raise valueerrortoken must be valid operator self attach(self root)leftrightuse inheritednonpublic method def str (self) """return string representation of the expression "" pieces sequence of piecewise strings to compose self parenthesize recur(self root)pieces return join(pieces def parenthesize recur(selfpresult) """append piecewise representation of subtree to resulting list "" if self is leaf( ) result append(str( element))leaf value as string elseopening parenthesis result appendleft subtree self parenthesize recur(self left( )result result append( element)operator right subtree self parenthesize recur(self right( )resultclosing parenthesis result appendcode fragment the beginning of an expressiontree class