enter= enter=stop adding parse tree interpreter one weakness in the parser program is that it embeds expression evaluation logic in the parsing logicthe result is computed while the string is being parsed this makes evaluation quickbut it can also make it difficult to modify the codeespecially in larger systems to simplifywe could restructure the program to keep expression parsing and evaluation separate instead of evaluating the stringthe parser can build up an intermediate representation of it that can be evaluated later as an added incentivebuilding the representation separately makes it available to other analysis tools ( optimizersviewersand so on)--they can be run as separate passes over the tree example - shows variant of parser that implements this idea the parser analyzes the string and builds up parse tree--that isa tree of class instances that represents the expression and that may be evaluated in separate step the parse tree is built from classes that "knowhow to evaluate themselvesto compute the expressionwe just ask the tree to evaluate itself root nodes in the tree ask their children to evaluate themselvesand then combine the results by applying single operator in effectevaluation in this version is simply recursive traversal of tree of embedded class instances constructed by the parser example - pp \lang\parser\parser py ""separate expression parsing from evaluation by building an explicit parse tree ""tracedefault false class undefinederror(exception)pass if __name__ ='__main__'from scanner import scannersyntaxerrorlexicalerror elsefrom scanner import scannersyntaxerrorlexicalerror if run here from pytree ################################################################################the interpreter ( smart objects tree################################################################################class treenodedef validate(selfdict)pass def apply(selfdict)pass def trace(selflevel)print(level ''default error check default evaluator default unparser custom language parsers