def visitIf_stmt(self, ctx: BKITParser.ProgramContext): list_stmt = ctx.list_statement().accept(self) ifthen_stmt = [(ctx.exp().accept(self), list_stmt[0], list_stmt[1])] else_if_stmt = list(map(lambda x: x.accept(self), ctx.else_if_stmt())) else_stmt = ([], []) if (ctx.else_stmt()): else_stmt = ctx.else_stmt().accept(self) return If(ifthen_stmt + else_if_stmt, else_stmt)
def visitDo_while_stmt(self, ctx: BKITParser.ProgramContext): list_stmt = ctx.list_statement().accept(self) return Dowhile(list_stmt, ctx.exp().accept(self))
def visitWhile_stmt(self, ctx: BKITParser.ProgramContext): list_stmt = ctx.list_statement().accept(self) return While(ctx.exp().accept(self), list_stmt)
def visitFor_stmt(self, ctx: BKITParser.ProgramContext): id = Id(ctx.ID().getText()) # [exp1,exp2,exp3] exp_list = list(map(lambda x: x.accept(self), ctx.exp())) list_stmt = ctx.list_statement().accept(self) return For(id, exp_list[0], exp_list[1], exp_list[2], list_stmt)
def visitElse_if_stmt(self, ctx: BKITParser.ProgramContext): list_stmt = ctx.list_statement().accept(self) return (ctx.exp().accept(self), list_stmt[0], list_stmt[1])
def visitElse_stmt(self, ctx: BKITParser.ProgramContext): return ctx.list_statement().accept(self)