示例#1
0
 def visitIf_stmt(self, ctx: MPParser.If_stmtContext):
     expr = self.visit(ctx.exp_bool())
     thenStmt = self.visit(ctx.stmt(0))
     if not isinstance(thenStmt, list): thenStmt = [thenStmt]
     if ctx.stmt(1):
         elseStmt = self.visit(ctx.stmt(1))
         if not isinstance(elseStmt, list): elseStmt = [elseStmt]
         return If(expr, thenStmt, elseStmt)
     return If(expr, thenStmt)
示例#2
0
 def visitIf_stmt(self, ctx: MPParser.If_stmtContext):
     if ctx.stmt(0).compound_stmt() is None:
         then_body = [self.visit(ctx.stmt(0))]
     else:
         then_body = self.visit(ctx.stmt(0))
     if ctx.getChildCount() == 6:
         if ctx.stmt(1).compound_stmt() is None:
             else_body = [self.visit(ctx.stmt(1))]
         else:
             else_body = self.visit(ctx.stmt(1))
         return If(self.visit(ctx.exp()), then_body, else_body)
     else:
         return If(self.visit(ctx.exp()), then_body, [])
示例#3
0
 def visitIf_stmt(self, ctx: MPParser.If_stmtContext):
     #if_stmt : IF exp THEN stmt (ELSE stmt)?;
     if ctx.ELSE():
         return If(self.visit(ctx.exp()), self.visit(ctx.stmt(0)),
                   self.visit(ctx.stmt(1)))
     else:
         return If(self.visit(ctx.exp()), self.visit(ctx.stmt(0)))
示例#4
0
 def visitIf_stmt(self, ctx: MPParser.If_stmtContext):
     return [
         If(self.visit(ctx.exp()), self.visit(ctx.statement(0)),
            self.visit(ctx.statement(1)) if ctx.statement(1) else [])
     ]