def term(self): r = None n = self.factor() if self.tkr.cur() in ['*', '/']: r = Node() r.val = self.tkr.get() if r.val == '*': r.type = 'mul' else: r.type = 'div' r.rhs = n r.lhs = self.term() else: r = n return r
def expr(self): r = None n = self.term() if self.tkr.cur() in ['+', '-']: r = Node() r.val = self.tkr.get() if r.val == '+': r.type = 'add' else: r.type = 'sub' r.rhs = n r.lhs = self.expr() else: r = n return r