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 visitExp8(self, ctx: BKITParser.ProgramContext): if (ctx.ID()): return Id(ctx.ID().getText()) if (ctx.getChildCount() == 3): return ctx.exp().accept(self) return ctx.literal().accept(self)
def visitIndex_exp(self, ctx: BKITParser.ProgramContext): exp7 = ctx.exp7().accept(self) if (ctx.getChildCount() == 1): return exp7 exp_list = list(map(lambda x: x.accept(self), ctx.exp())) return ArrayCell(exp7, exp_list)
def visitProgram(self, ctx: BKITParser.ProgramContext): return self.visitExp(ctx.exp())
def visitExps_list(self, ctx: BKITParser.ProgramContext): return list(map(lambda x: x.accept(self), ctx.exp()))
def visitReturn_stmt(self, ctx: BKITParser.ProgramContext): exp = None if (ctx.exp()): exp = ctx.exp().accept(self) return Return(exp)
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 visitAssign_body(self, ctx: BKITParser.ProgramContext): return Assign(ctx.assign_head().accept(self), ctx.exp().accept(self))
def visitProgram(self, ctx: BKITParser.ProgramContext): return ctx.exp().accept(self)