Example #1
0
 def visitAdditiveExpression(
         self, ctx: JavaScriptParser.AdditiveExpressionContext):
     if ctx.children[1].getText() == "+":
         add_operator = operators.BinaryOperator.ADDITION
     elif ctx.children[1].getText() == "-":
         add_operator = operators.BinaryOperator.SUBTRACTION
     else:
         add_operator = None
     return nodes.BinaryExpression(ctx, add_operator,
                                   self.visit(ctx.singleExpression(0)),
                                   self.visit(ctx.singleExpression(1)))
Example #2
0
 def visitEqualityExpression(
         self, ctx: JavaScriptParser.EqualityExpressionContext):
     operator_str = ctx.children[1].getText()
     if operator_str == "===":
         unary_operator = operators.BinaryOperator.EQUAL
     elif operator_str == "!==":
         unary_operator = operators.BinaryOperator.UNEQUAL
     else:
         unary_operator = None
     return nodes.BinaryExpression(ctx, unary_operator,
                                   self.visit(ctx.singleExpression(0)),
                                   self.visit(ctx.singleExpression(1)))
Example #3
0
 def visitBitShiftExpression(
         self, ctx: JavaScriptParser.BitShiftExpressionContext):
     if ctx.children[1].getText() == "<<":
         shift_operator = operators.BinaryOperator.LEFT_SHIFT
     elif ctx.children[1].getText() == ">>":
         shift_operator = operators.BinaryOperator.RIGHT_SHIFT
     elif ctx.children[1].getText() == ">>>":
         shift_operator = operators.BinaryOperator.ARITHMETIC_RIGHT_SHIFT
     else:
         shift_operator = None
     return nodes.BinaryExpression(ctx, shift_operator,
                                   self.visit(ctx.singleExpression(0)),
                                   self.visit(ctx.singleExpression(1)))
Example #4
0
 def visitMultiplicativeExpression(
         self, ctx: JavaScriptParser.MultiplicativeExpressionContext):
     if ctx.children[1].getText() == "/":
         multi_operator = operators.BinaryOperator.DIVISION
     elif ctx.children[1].getText() == "*":
         multi_operator = operators.BinaryOperator.MULTIPLICATION
     elif ctx.children[1].getText() == "%":
         multi_operator = operators.BinaryOperator.REMAINDER
     else:
         multi_operator = None
     return nodes.BinaryExpression(ctx, multi_operator,
                                   self.visit(ctx.singleExpression(0)),
                                   self.visit(ctx.singleExpression(1)))
Example #5
0
 def visitRelationalExpression(
         self, ctx: JavaScriptParser.RelationalExpressionContext):
     if ctx.children[1].getText() == "<":
         relational_operator = operators.BinaryOperator.LESS
     elif ctx.children[1].getText() == "<=":
         relational_operator = operators.BinaryOperator.LESS_OR_EQUAL
     elif ctx.children[1].getText() == ">":
         relational_operator = operators.BinaryOperator.GREATER
     elif ctx.children[1].getText() == ">=":
         relational_operator = operators.BinaryOperator.GREATER_OR_EQUAL
     else:
         relational_operator = None
     return nodes.BinaryExpression(ctx, relational_operator,
                                   self.visit(ctx.singleExpression(0)),
                                   self.visit(ctx.singleExpression(1)))
Example #6
0
 def visitBitOrExpression(self,
                          ctx: JavaScriptParser.BitOrExpressionContext):
     return nodes.BinaryExpression(ctx, operators.BinaryOperator.BIT_OR,
                                   self.visit(ctx.singleExpression(0)),
                                   self.visit(ctx.singleExpression(1)))