Пример #1
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())
Пример #2
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())
Пример #3
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()))