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
def factor(self): n = None if self.tkr.cur() == '(': self.tkr.get() n = self.expr() self.tkr.get() else: n = Node() n.val = int(self.tkr.get()) n.type = 'number' return n