def multiplication(self): curr_expr = self.unary() mult_ops = [TokenType.STAR, TokenType.SLASH, TokenType.PERCENT] while self.curr_token_is(mult_ops): operator = self.pop_token() right_side = self.unary() curr_expr = Expression.Binary(curr_expr, operator, right_side) return curr_expr
def addition(self): curr_expr = self.multiplication() addition_ops = [TokenType.MINUS, TokenType.PLUS] while self.curr_token_is(addition_ops): operator = self.pop_token() right_side = self.multiplication() curr_expr = Expression.Binary(curr_expr, operator, right_side) return curr_expr
def equality(self): curr_expr = self.comparison() equality_ops = [TokenType.EQUAL_EQUAL, TokenType.BANG_EQUAL] while self.curr_token_is(equality_ops): operator = self.pop_token() right_side = self.comparison() curr_expr = Expression.Binary(curr_expr, operator, right_side) return curr_expr
def logical_ops(self): curr_expr = self.equality() logical_ops = [TokenType.OR, TokenType.AND] while self.curr_token_is(logical_ops): operator = self.pop_token() right_side = self.equality() curr_expr = Expression.Binary(curr_expr, operator, right_side) return curr_expr
def comparison(self): curr_expr = self.addition() compare_ops = [ TokenType.LESS, TokenType.LESS_EQUAL, TokenType.GREATER, TokenType.GREATER_EQUAL ] while self.curr_token_is(compare_ops): operator = self.pop_token() right_side = self.addition() curr_expr = Expression.Binary(curr_expr, operator, right_side) return curr_expr