def a_expr(self): m_expr = self.m_expr() v = m_expr while self._peek(self.a_expr_rsts) in self.a_expr_chks: _token_ = self._peek(self.a_expr_chks) if _token_ == 'ADD': ADD = self._scan('ADD') m_expr = self.m_expr() v = BinaryOp(operator.add, v, m_expr) else: # == 'SUB' SUB = self._scan('SUB') m_expr = self.m_expr() v = BinaryOp(operator.sub, v, m_expr) return v
def m_expr(self): u_expr = self.u_expr() v = u_expr while self._peek(self.m_expr_rsts) in self.m_expr_chks: _token_ = self._peek(self.m_expr_chks) if _token_ == 'MUL': MUL = self._scan('MUL') u_expr = self.u_expr() v = BinaryOp(operator.mul, v, u_expr) else: # == 'DIV' DIV = self._scan('DIV') u_expr = self.u_expr() v = BinaryOp(operator.truediv, v, u_expr) return v
def comparison(self): a_expr = self.a_expr() v = a_expr while self._peek(self.comparison_rsts) in self.comparison_chks: _token_ = self._peek(self.comparison_chks) if _token_ == 'LT': LT = self._scan('LT') a_expr = self.a_expr() v = BinaryOp(operator.lt, v, a_expr) elif _token_ == 'GT': GT = self._scan('GT') a_expr = self.a_expr() v = BinaryOp(operator.gt, v, a_expr) elif _token_ == 'LE': LE = self._scan('LE') a_expr = self.a_expr() v = BinaryOp(operator.le, v, a_expr) elif _token_ == 'GE': GE = self._scan('GE') a_expr = self.a_expr() v = BinaryOp(operator.ge, v, a_expr) elif _token_ == 'EQ': EQ = self._scan('EQ') a_expr = self.a_expr() v = BinaryOp(operator.eq, v, a_expr) else: # == 'NE' NE = self._scan('NE') a_expr = self.a_expr() v = BinaryOp(operator.ne, v, a_expr) return v