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
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 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 p_logical_expr2(p): '''logical_expr : NOT expr ''' p[0]=Node('NOT') p[0].val = p[2]