Exemplo n.º 1
0
 def visitIf_stmt(self, ctx: MCParser.If_stmtContext):
     expr = self.visit(ctx.exp())
     then_stmt = self.visit(ctx.stmt(0))
     else_stmt = None
     if ctx.stmt(1):
         else_stmt = self.visit(ctx.stmt(1))
     return If(expr, then_stmt, else_stmt)
Exemplo n.º 2
0
 def visitIf_stmt(self, ctx: MCParser.If_stmtContext):
     if (ctx.ELSE()):
         expr = self.visit(ctx.expr())
         stmt0 = self.visit(ctx.stmt(0))
         stmt1 = self.visit(ctx.stmt(1))
         return If(expr, stmt0, stmt1)
     else:
         expr = self.visit(ctx.expr())
         stmt0 = self.visit(ctx.stmt(0))
         return If(expr, stmt0)
Exemplo n.º 3
0
    def visitIf_stmt(self, ctx: MCParser.If_stmtContext):

        expr = self.visit(ctx.exp())
        #because ctx.stmt(1) is a list, so need a index [0]
        thenStmt = self.visit(ctx.stmt(0))[0]
        if ctx.stmt(1):
            elseStmt = self.visit(ctx.stmt(1))[0]
            return If(expr, thenStmt, elseStmt)
        else:
            return If(expr, thenStmt)
Exemplo n.º 4
0
 def visitIf_stmt(self, ctx: MCParser.If_stmtContext):
     return self.visit(ctx.getChild(0))
Exemplo n.º 5
0
 def visitIf_stmt(self, ctx:MCParser.If_stmtContext):
     # if_stmt : IF LP expr RP statement (ELSE statement)?;
     return If(self.visit(ctx.expr()),self.visit(ctx.statement(0))) if ctx.getChildCount() == 5 else If(self.visit(ctx.expr()),self.visit(ctx.statement(0)),self.visit(ctx.statement(1)))
Exemplo n.º 6
0
 def visitIf_stmt(self, ctx: MCParser.If_stmtContext):
     return If(self.visit(ctx.expr()), self.visit(ctx.stmt(0)),
               self.visit(ctx.stmt(1)) if ctx.ELSE() else None)
Exemplo n.º 7
0
 def visitIf_stmt(self, ctx:MCParser.If_stmtContext):
     if ctx.IF() and ctx.ELSE():
         return If(self.visitExp(ctx.exp()), self.visitStmt(ctx.stmt(0)), self.visitStmt(ctx.stmt(1)))
     else:
         return If(self.visitExp(ctx.exp()), self.visitStmt(ctx.stmt(0)))
Exemplo n.º 8
0
 def visitIf_stmt(self, ctx: MCParser.If_stmtContext):
     expr = self.visit(ctx.expression())
     thenStmt = self.visit(ctx.getChild(4))
     elseStmt = self.visit(ctx.getChild(6)) if ctx.ELSE() else None
     return If(expr, thenStmt, elseStmt)