def expr(self): node = self.term() if self.is_next(Type.BinaryOperation.Or): while self.token.type in (Type.BinaryOperation.Or): operation_token = self.token self.next_token() new_node = self.term() node = Node.BinaryOperation(node, new_node, operation_token) else: while self.token.type in (Type.BinaryOperation.Plus, Type.BinaryOperation.Minus): operation_token = self.token self.next_token() new_node = self.term() node = Node.BinaryOperation(node, new_node, operation_token) return node
def term(self): node = self.factor() if self.is_next(Type.BinaryOperation.And): while self.token.type in (Type.BinaryOperation.And): operation_token = self.token self.next_token() new_node = self.factor() node = Node.BinaryOperation(node, new_node, operation_token) else: while self.token.type in (Type.BinaryOperation.Mul, Type.BinaryOperation.Div, Type.BinaryOperation.Mod, Type.BinaryOperation.DivInt): operation_token = self.token self.next_token() new_node = self.factor() node = Node.BinaryOperation(node, new_node, operation_token) return node
def comparing_expr(self): handle_operations = [ Type.BinaryOperation.Equal, Type.BinaryOperation.NotEqual, Type.BinaryOperation.Less, Type.BinaryOperation.LessEqual, Type.BinaryOperation.Bigger, Type.BinaryOperation.BiggerEqual, ] node = self.expr() if self.is_next(handle_operations): operation_token = self.token self.next_token() new_node = self.expr() node = Node.BinaryOperation(node, new_node, operation_token) return node