示例#1
0
    def _parse_expression(self, parent_precedence=0):
        unary_operator_precedence = SyntaxKind.get_unary_operator_precedence(
            self._get_current_token().get_kind())

        if unary_operator_precedence != 0 and unary_operator_precedence >= parent_precedence:
            operator_token = self._next_token()
            operand = self._parse_expression(unary_operator_precedence)
            left = UnaryExpressionSyntax(operator_token, operand)

        else:
            left = self._parse_primary()

        while True:
            precedence = SyntaxKind.get_binary_operator_precedence(
                self._get_current_token().get_kind())

            if precedence == 0 or precedence <= parent_precedence:
                break

            operator_token = self._next_token()
            right = self._parse_expression(precedence)
            left = BinaryExpressionSyntax(left, operator_token, right)

        return left
示例#2
0
 def test_binary_operators(self):
     for i in SyntaxKind.str:
         if SyntaxKind.get_binary_operator_precedence(i) > 0:
             pass