Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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