Exemple #1
0
 def visitExp2(self, ctx: MPParser.Exp2Context):
     if ctx.getChildCount() == 1:  # exp3
         return self.visit(ctx.exp3())
     left = self.visit(ctx.exp2())
     right = self.visit(ctx.exp3())
     op = ctx.getChild(1).getText()
     return BinaryOp(op, left, right)
 def visitExp2(self, ctx: MPParser.Exp2Context):
     '''exp2: exp2 ADD exp3 | exp2 SUB exp3 | exp2 OR exp3 | exp3;'''
     return BinaryOp(
         ctx.getChild(1).getText(), self.visit(ctx.exp2()),
         self.visit(
             ctx.exp3())) if ctx.getChildCount() == 3 else self.visit(
                 ctx.exp3())
 def visitExp2(self, ctx: MPParser.Exp2Context):
     if ctx.getChildCount() == 1:
         return self.visit(ctx.exp3())
     else:
         return BinaryOp(
             ctx.getChild(1).getText(), self.visit(ctx.exp2()),
             self.visit(ctx.exp3()))
Exemple #4
0
 def visitExp2(self, ctx:MPParser.Exp2Context):
     if ctx.getChildCount() == 3:
         exp0 = self.visit(ctx.exp2())
         exp1 = self.visit(ctx.exp3())
         op = self.visit(ctx.additiveOperator())
         return BinaryOp(op,exp0,exp1)
     else:
         return self.visit(ctx.exp3())
Exemple #5
0
    def visitExp2(self, ctx: MPParser.Exp2Context):

        if ctx.getChildCount() == 1:
            return self.visit(ctx.exp3())
        op = ctx.getChild(1).getText()
        exp2 = self.visit(ctx.exp2())
        exp3 = self.visit(ctx.exp3())
        return BinaryOp(op, exp2, exp3)
Exemple #6
0
 def visitExp2(self, ctx: MPParser.Exp2Context):
     op = ""
     if ctx.ADDOP(): op = ctx.ADDOP().getText()
     elif ctx.SUBOP(): op = ctx.SUBOP().getText()
     elif ctx.OR(): op = ctx.OR().getText()
     else: return self.visit(ctx.exp3())
     return BinaryOp(op, self.visit(ctx.exp2()), self.visit(ctx.exp3()))
Exemple #7
0
 def visitExp2(self, ctx: MPParser.Exp2Context):
     log('visitExp2')
     if ctx.getChildCount() == 1:  # exp3
         return self.visit(ctx.exp3())
     left = self.visit(ctx.exp2())
     right = self.visit(ctx.exp3())
     op = ctx.getChild(1).getText()
     log1(left)
     log1(right)
     log1(op)
     return BinaryOp(op, left, right)
     return self.visitChildren(ctx)
Exemple #8
0
 def visitExp2(self, ctx: MPParser.Exp2Context):
     if ctx.ADDOP():
         return BinaryOp('+', self.visit(ctx.exp2()),
                         self.visit(ctx.exp3()))
     elif ctx.SUBOP():
         return BinaryOp('-', self.visit(ctx.exp2()),
                         self.visit(ctx.exp3()))
     elif ctx.OROP():
         return BinaryOp(ctx.OROP().getText(), self.visit(ctx.exp2()),
                         self.visit(ctx.exp3()))
     else:
         return self.visit(ctx.exp3())
Exemple #9
0
 def visitExp2(self, ctx: MPParser.Exp2Context):
     if ctx.getChildCount() == 3:
         if ctx.MULOP():
             return BinaryOp(ctx.MULOP().getText(), self.visit(ctx.exp2()),
                             self.visit(ctx.exp3()))
         elif ctx.DIVOP():
             return BinaryOp(ctx.DIVOP().getText(), self.visit(ctx.exp2()),
                             self.visit(ctx.exp3()))
         elif ctx.DIVINOP():
             return BinaryOp(ctx.DIVINOP().getText(),
                             self.visit(ctx.exp2()), self.visit(ctx.exp3()))
         elif ctx.MODOP():
             return BinaryOp(ctx.MODOP().getText(), self.visit(ctx.exp2()),
                             self.visit(ctx.exp3()))
         elif ctx.ANDOP():
             return BinaryOp(ctx.ANDOP().getText(), self.visit(ctx.exp2()),
                             self.visit(ctx.exp3()))
     else:
         return self.visit(ctx.exp3())
Exemple #10
0
 def visitExp2(self, ctx: MPParser.Exp2Context):
     if (ctx.EQ()):
         return BinaryOp("=", self.visit(ctx.exp3(0)),
                         self.visit(ctx.exp3(1)))
     elif (ctx.NOTEQ()):
         return BinaryOp("<>", self.visit(ctx.exp3(0)),
                         self.visit(ctx.exp3(1)))
     elif (ctx.LESSTN()):
         return BinaryOp("<", self.visit(ctx.exp3(0)),
                         self.visit(ctx.exp3(1)))
     elif (ctx.GRETN()):
         return BinaryOp(">", self.visit(ctx.exp3(0)),
                         self.visit(ctx.exp3(1)))
     elif (ctx.GREEQ()):
         return BinaryOp(">=", self.visit(ctx.exp3(0)),
                         self.visit(ctx.exp3(1)))
     elif (ctx.LESSEQ()):
         return BinaryOp("<=", self.visit(ctx.exp3(0)),
                         self.visit(ctx.exp3(1)))
     else:
         return self.visit(ctx.exp3(0))