Пример #1
0
 def visitExp1(self, ctx: MPParser.Exp1Context):
     if ctx.getChildCount() == 1:
         return self.visit(ctx.exp2(0))
     else:
         return BinaryOp(
             ctx.getChild(1).getText(), self.visit(ctx.exp2(0)),
             self.visit(ctx.exp2(1)))
Пример #2
0
 def visitExp1(self, ctx: MPParser.Exp1Context):
     if ctx.getChildCount() == 1:  # exp2
         return self.visit(ctx.exp2(0))
     left = self.visit(ctx.exp2(0))
     right = self.visit(ctx.exp2(1))
     op = ctx.getChild(1).getText()
     return BinaryOp(op, left, right)
 def visitExp1(self, ctx: MPParser.Exp1Context):
     '''exp1: exp2 EQUAL exp2 | exp2 NOTEQUAL exp2 | exp2 LESSTHAN exp2 | exp2 GREATERTHAN exp2 | exp2 LESSEQUAL exp2 | exp2 GREATEREQUAL exp2 | exp2;'''
     return BinaryOp(
         ctx.getChild(1).getText(), self.visit(ctx.exp2(0)),
         self.visit(
             ctx.exp2(1))) if ctx.getChildCount() == 3 else self.visit(
                 ctx.exp2(0))
Пример #4
0
 def visitExp1(self, ctx:MPParser.Exp1Context):
     if ctx.getChildCount() == 3:
         exp0 = self.visit(ctx.exp2(0))
         exp1 = self.visit(ctx.exp2(1))
         op = self.visit(ctx.relationalOperator())
         return BinaryOp(op,exp0,exp1)
     else:
         return self.visit(ctx.exp2(0))
Пример #5
0
    def visitExp1(self, ctx: MPParser.Exp1Context):
        if ctx.getChildCount() == 1:
            return self.visit(ctx.exp2(0))

        op = ctx.getChild(1).getText()
        exp2_1 = self.visit(ctx.exp2(0))
        exp2_2 = self.visit(ctx.exp2(1))
        return BinaryOp(op, exp2_1, exp2_2)
Пример #6
0
 def visitExp1(self, ctx: MPParser.Exp1Context):
     if (ctx.AND() and ctx.THEN()):
         return BinaryOp("andthen", self.visit(ctx.exp1()),
                         self.visit(ctx.exp2()))
     elif (ctx.OR() and ctx.ELSE()):
         return BinaryOp("orelse", self.visit(ctx.exp1()),
                         self.visit(ctx.exp2()))
     else:
         return self.visit(ctx.exp2())
Пример #7
0
 def visitExp1(self, ctx:MPParser.Exp1Context):
     if ctx.exp1() is None:
         a=ctx.exp2()
         return self.visit(ctx.exp2())
     else:
         if ctx.AND() is None:
             return BinaryOp("orelse",self.visit(ctx.exp1()),self.visit(ctx.exp2()))
         else:
             return BinaryOp("andthen",self.visit(ctx.exp1()),self.visit(ctx.exp2()))
Пример #8
0
 def visitExp1(self, ctx: MPParser.Exp1Context):
     if ctx.EQUOP():
         return BinaryOp('=', self.visit(ctx.exp2(0)),
                         self.visit(ctx.exp2(1)))
     elif ctx.NEOP():
         return BinaryOp('<>', self.visit(ctx.exp2(0)),
                         self.visit(ctx.exp2(1)))
     elif ctx.LTOP():
         return BinaryOp('<', self.visit(ctx.exp2(0)),
                         self.visit(ctx.exp2(1)))
     elif ctx.LTEOP():
         return BinaryOp('<=', self.visit(ctx.exp2(0)),
                         self.visit(ctx.exp2(1)))
     elif ctx.MTOP():
         return BinaryOp('>', self.visit(ctx.exp2(0)),
                         self.visit(ctx.exp2(1)))
     elif ctx.MTEOP():
         return BinaryOp('>=', self.visit(ctx.exp2(0)),
                         self.visit(ctx.exp2(1)))
     else:
         return self.visit(ctx.exp2(0))
Пример #9
0
    def visitExp1(self, ctx: MPParser.Exp1Context):
        #exp1 ADDOP exp2| exp1 OROP exp2  | exp2;

        # if ctx.ADDOP():
        #     return BinaryOp(ctx.ADDOP().getText(),
        #                     self.visit(ctx.exp1()),
        #                     self.visit(ctx.exp2()))
        # elif ctx.OROP():
        #     return BinaryOp(ctx.OROP().getText(),
        #                     self.visit(ctx.exp1()),
        #                     self.visit(ctx.exp2()))
        # else:
        #     return self.visit(ctx.exp2())
        if ctx.getChildCount() == 3:
            if ctx.ADDOP():
                return BinaryOp(ctx.ADDOP().getText(), self.visit(ctx.exp1()),
                                self.visit(ctx.exp2()))
            elif ctx.SUBOP():
                return BinaryOp(ctx.SUBOP().getText(), self.visit(ctx.exp1()),
                                self.visit(ctx.exp2()))
            elif ctx.OROP():
                return BinaryOp(ctx.OROP().getText(), self.visit(ctx.exp1()),
                                self.visit(ctx.exp2()))
        else:
            return self.visit(ctx.exp2())
Пример #10
0
 def visitExp1(self, ctx:MPParser.Exp1Context):
     op = ""
     if ctx.EQOP(): op = ctx.EQOP().getText()
     elif ctx.NEQOP(): op = ctx.NEQOP().getText()
     elif ctx.LTOP(): op = ctx.LTOP().getText()
     elif ctx.LTEOP(): op = ctx.LTEOP().getText()
     elif ctx.GTOP(): op = ctx.GTOP().getText()
     elif ctx.GTEOP(): op = ctx.GTEOP().getText()
     else: return self.visit(ctx.exp2(0))
     
     return BinaryOp(op,self.visit(ctx.exp2(0)),self.visit(ctx.exp2(1)))
Пример #11
0
 def visitExp1(self, ctx: MPParser.Exp1Context):
     if ctx.getChildCount() == 3:
         if ctx.EQUAL():
             return BinaryOp(ctx.EQUAL().getText(), self.visit(ctx.exp2(0)),
                             self.visit(ctx.exp2(1)))
         elif ctx.NOTEQUAL():
             return BinaryOp(ctx.NOTEQUAL().getText(),
                             self.visit(ctx.exp2(0)),
                             self.visit(ctx.exp2(1)))
         elif ctx.LESS():
             return BinaryOp(ctx.LESS().getText(), self.visit(ctx.exp2(0)),
                             self.visit(ctx.exp2(1)))
         elif ctx.LESSEQUAL():
             return BinaryOp(ctx.LESSEQUAL().getText(),
                             self.visit(ctx.exp2(0)),
                             self.visit(ctx.exp2(1)))
         elif ctx.GREATER():
             return BinaryOp(ctx.GREATER().getText(),
                             self.visit(ctx.exp2(0)),
                             self.visit(ctx.exp2(1)))
         elif ctx.GREATEREQUAL():
             return BinaryOp(ctx.GREATEREQUAL().getText(),
                             self.visit(ctx.exp2(0)),
                             self.visit(ctx.exp2(1)))
     else:
         return self.visit(ctx.exp2(0))