Ejemplo n.º 1
0
 def visitExp4(self, ctx: MPParser.Exp4Context):
     if ctx.SUBOP():
         return UnaryOp('-', self.visit(ctx.exp4()))
     elif ctx.NOTOP():
         return UnaryOp(ctx.NOTOP().getText(), self.visit(ctx.exp4()))
     else:
         return self.visit(ctx.operand())
Ejemplo n.º 2
0
 def visitExp4(self, ctx: MPParser.Exp4Context):
     if ctx.getChildCount() == 1:
         return self.visit(ctx.exp5())
     if ctx.SUB():
         return UnaryOp(ctx.SUB().getText(), self.visit(ctx.exp4()))
     if ctx.NOT():
         return UnaryOp(ctx.NOT().getText(), self.visit(ctx.exp4()))
Ejemplo n.º 3
0
 def visitExp4(self, ctx: MPParser.Exp4Context):
     if ctx.exp4() is None:
         return self.visit(ctx.exp5())
     else:
         return BinaryOp(
             ctx.getChild(1).getText(), self.visit(ctx.exp4()),
             self.visit(ctx.exp5()))
Ejemplo n.º 4
0
 def visitExp4(self, ctx: MPParser.Exp4Context):
     if (ctx.SUB() or ctx.NOT()):
         if ctx.SUB():
             return UnaryOp(ctx.SUB().getText(), self.visit(ctx.exp4()))
         elif ctx.NOT():
             return UnaryOp(ctx.NOT().getText(), self.visit(ctx.exp4()))
     else:
         return self.visit(ctx.exp5())
Ejemplo n.º 5
0
    def visitExp4(self, ctx:MPParser.Exp4Context):
        op = ""
        if ctx.SUBOP(): op = ctx.SUBOP().getText()
        elif ctx.NOT(): op = ctx.NOT().getText()
        else: return self.visit(ctx.exp5())

        return UnaryOp(op, self.visit(ctx.exp4()))
Ejemplo n.º 6
0
 def visitExp4(self, ctx:MPParser.Exp4Context):
     if ctx.getChildCount() == 2:
         op = ctx.getChild(0).getText()
         body = self.visit(ctx.exp4())
         return UnaryOp(op,body)
     else:
         return self.visit(ctx.exp6())
Ejemplo n.º 7
0
 def visitExp4(self, ctx: MPParser.Exp4Context):
     log('visitExp4')
     if ctx.getChildCount() == 1:
         return self.visit(ctx.operands())
     op = ctx.NOT().getText() if ctx.NOT() else ctx.SUB().getText()
     body = self.visit(ctx.exp4())
     log1(body)
     log1(op)
     return UnaryOp(op, body)
Ejemplo n.º 8
0
 def visitExp4(self, ctx: MPParser.Exp4Context):
     if (ctx.DIVSI()):
         return BinaryOp("/", self.visit(ctx.exp4()),
                         self.visit(ctx.exp5()))
     elif (ctx.MUL()):
         return BinaryOp("*", self.visit(ctx.exp4()),
                         self.visit(ctx.exp5()))
     elif (ctx.MOD()):
         mod = ctx.MOD().getText()
         return BinaryOp(mod, self.visit(ctx.exp4()),
                         self.visit(ctx.exp5()))
     elif (ctx.AND()):
         return BinaryOp(ctx.AND().getText(), self.visit(ctx.exp4()),
                         self.visit(ctx.exp5()))
     elif (ctx.DIV()):
         return BinaryOp(ctx.DIV().getText(), self.visit(ctx.exp4()),
                         self.visit(ctx.exp5()))
     else:
         return self.visit(ctx.exp5())
Ejemplo n.º 9
0
 def visitExp4(self, ctx: MPParser.Exp4Context):
     if ctx.getChildCount() == 1:
         return self.visitChildren(ctx)
     return UnaryOp(ctx.getChild(0).getText(), self.visit(ctx.exp4()))
Ejemplo n.º 10
0
 def visitExp4(self, ctx: MPParser.Exp4Context):
     if ctx.getChildCount() == 1:
         return self.visit(ctx.exp5())
     op = ctx.getChild(0).getText()
     exp4 = self.visit(ctx.exp4())
     return UnaryOp(op, exp4)
Ejemplo n.º 11
0
 def visitExp4(self, ctx: MPParser.Exp4Context):
     '''exp4: SUB exp4 | NOT exp4 | exp5;'''
     return UnaryOp(ctx.getChild(0).getText(), self.visit(
         ctx.exp4())) if ctx.getChildCount() == 2 else self.visit(
             ctx.exp5())