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 visitVariable(self, ctx: BKITParser.ProgramContext): variable = { "id": Id(''), "dimension": [], } # a if (ctx.ID()): variable['id'] = Id(ctx.ID().getText()) return variable # a[3][4] variable = ctx.array_type().accept(self) return variable
def visitFunc_declare(self, ctx: BKITParser.ProgramContext): id = Id(ctx.ID().getText()) param_list = [] if (ctx.param_declare()): param_list = ctx.param_declare().accept(self) tuple_statement = ctx.body().accept(self) return FuncDecl(id, param_list, tuple_statement)
def visitArray_type(self, ctx: BKITParser.ProgramContext): variable = { "id": Id(ctx.ID().getText()), "dimension": [], } # calc dimension listOfDimension = list( map(lambda x: int(x.getText(), 0), ctx.INTEGER_LITERAL())) variable['dimension'] = listOfDimension return variable
def visitExp7(self, ctx: BKITParser.ProgramContext): if (ctx.getChildCount() == 1): return ctx.exp8().accept(self) exps_list = ctx.exps_list().accept(self) return CallExpr(Id(ctx.ID().getText()), exps_list)
def visitCall_stmt(self, ctx: BKITParser.ProgramContext): exps_list = ctx.exps_list().accept(self) return CallStmt(Id(ctx.ID().getText()), exps_list)
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 visitAssign_head(self, ctx: BKITParser.ProgramContext): if (ctx.ID() != None): return Id(ctx.ID().getText()) return ctx.index_exp().accept(self)
def visitProgram(self, ctx: BKITParser.ProgramContext): return Program([VarDecl(Id(ctx.ID().getText()), [], None)])