Пример #1
0
 def visitExpression1(self, ctx: MPParser.Expression1Context):
     #print("expr1")
     if ctx.getChildCount() == 1:
         return self.visitChildren(ctx)
     else:
         return BinaryOp(
             ctx.getChild(1).getText(), self.visit(ctx.expression2(0)),
             self.visit(ctx.expression2(1)))
Пример #2
0
 def visitExpression1(self, ctx: MPParser.Expression1Context):
     if (ctx.getChildCount() == 3):
         if ctx.EQ():
             return BinaryOp("=", self.visit(ctx.simpleExpression1(0)),
                             self.visit(ctx.simpleExpression1(1)))
         elif ctx.NOTEQ():
             return BinaryOp("<>", self.visit(ctx.simpleExpression1(0)),
                             self.visit(ctx.simpleExpression1(1)))
         elif ctx.LESS():
             return BinaryOp("<", self.visit(ctx.simpleExpression1(0)),
                             self.visit(ctx.simpleExpression1(1)))
         elif ctx.GREATER():
             return BinaryOp(">", self.visit(ctx.simpleExpression1(0)),
                             self.visit(ctx.simpleExpression1(1)))
         elif ctx.LEQ():
             return BinaryOp("<=", self.visit(ctx.simpleExpression1(0)),
                             self.visit(ctx.simpleExpression1(1)))
         else:
             return BinaryOp(">=", self.visit(ctx.simpleExpression1(0)),
                             self.visit(ctx.simpleExpression1(1)))
     else:
         return self.visit(ctx.simpleExpression1(0))
Пример #3
0
 def visitExpression1(self, ctx: MPParser.Expression1Context):
     op = ""
     if ctx.EQUAL():
         op = ctx.EQUAL().getText()
     elif ctx.NOT_EQUAL():
         op = ctx.NOT_EQUAL().getText()
     elif ctx.LT():
         op = ctx.LT().getText()
     elif ctx.LE():
         op = ctx.LE().getText()
     elif ctx.GT():
         op = ctx.GT().getText()
     elif ctx.GE():
         op = ctx.GE().getText()
     else:
         return self.visit(ctx.expression2(0))
     left = self.visit(ctx.expression2(0))
     right = self.visit(ctx.expression2(1))
     return BinaryOp(op, left, right)
Пример #4
0
 def visitExpression1(self, ctx: MPParser.Expression1Context):
     #expression1:expression2 EQ expression2| expression2 NOTEQ expression2| expression2 LESS expression2
     #| expression2 GREATER expression2| expression2 LEQ expression2| expression2 GEQ expression2 | expression2
     if ctx.EQ():
         return BinaryOp("=", self.visit(ctx.expression2(0)),
                         self.visit(ctx.expression2(1)))
     elif ctx.NOTEQ():
         return BinaryOp("<>", self.visit(ctx.expression2(0)),
                         self.visit(ctx.expression2(1)))
     elif ctx.LESS():
         return BinaryOp("<", self.visit(ctx.expression2(0)),
                         self.visit(ctx.expression2(1)))
     elif ctx.GREATER():
         return BinaryOp(">", self.visit(ctx.expression2(0)),
                         self.visit(ctx.expression2(1)))
     elif ctx.LEQ():
         return BinaryOp("<=", self.visit(ctx.expression2(0)),
                         self.visit(ctx.expression2(1)))
     elif ctx.GEQ():
         return BinaryOp(">=", self.visit(ctx.expression2(0)),
                         self.visit(ctx.expression2(1)))
     else:
         return self.visit(ctx.expression2(0))  #ctx.expression2() thì error