self lex showerror(def interpret(selftree)result tree apply(self varsif result !noneprint(resultreturns none tree evals itself ignore 'setresult ignores errors def goal(self)if self lex token in ['num''var''(']tree self expr(self lex match('\ 'return tree elif self lex token ='set'tree self assign(self lex match('\ 'return tree elseraise syntaxerror(def assign(self)self lex match('set'vartree varnode(self lex valueself lex startself lex match('var'valtree self expr(return assignnode(vartreevaltreetwo subtrees def expr(self)left self factor(while trueif self lex token in ['\ '')']return left elif self lex token ='+'self lex scan(left plusnode(leftself factor()elif self lex token ='-'self lex scan(left minusnode(leftself factor()elseraise syntaxerror(def factor(self)left self term(while trueif self lex token in ['+''-''\ '')']return left elif self lex token ='*'self lex scan(left timesnode(leftself term()elif self lex token ='/'self lex scan(left dividenode(leftself term()elseraise syntaxerror( text and language left subtree add root-node grows up/right