def visitExp2(self, ctx: BKITParser.ProgramContext): if (ctx.getChildCount() == 1): return ctx.exp3().accept(self) return BinaryOp( ctx.getChild(1).getText(), ctx.exp2().accept(self), ctx.exp3().accept(self))
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 visitProgram(self, ctx: BKITParser.ProgramContext): if ctx.getChildCount() == 1: return Program([]) else: listDecl = [] for i in range(ctx.getChildCount() - 1): listDecl += self.visit(ctx.getChild(i)) return Program(listDecl)
def visitProgram(self, ctx: BKITParser.ProgramContext): lst = [] if ctx.glovardeclprt(): lst = lst + self.visit(ctx.glovardeclprt()) + self.visit( ctx.funcdeclprt()) else: lst = lst + self.visit(ctx.funcdeclprt()) return Program(lst)
def visitProgram(self, ctx: BKITParser.ProgramContext): var_decls = list( reduce(lambda y, x: y + self.visitVar_declare(x), [item for item in ctx.var_declare()], [])) funcs_decls = list( reduce(lambda y, x: y + self.visitFunction_declare(x), [item for item in ctx.function_declare()], [])) return Program(var_decls + funcs_decls)
def visitVariable_assign(self, ctx: BKITParser.ProgramContext): variable = ctx.variable().accept(self) # variable ASSIGN literals if (ctx.getChildCount() == 3): literal = ctx.literal().accept(self) return VarDecl(variable['id'], variable['dimension'], ctx.literal().accept(self)) # variable return VarDecl(variable['id'], variable['dimension'], None)
def visitExp3(self, ctx: BKITParser.ProgramContext): # right association should be calced first ? if (ctx.getChildCount() == 1): return ctx.exp4().accept(self) return BinaryOp( ctx.getChild(1).getText(), ctx.exp3().accept(self), ctx.exp4().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 Program([VarDecl(Id(ctx.ID().getText()),[],None)]) var_dcl_list = list( functools.reduce( lambda a, b: a + b, map(lambda var_dcl: var_dcl.accept(self), ctx.var_dcl()), [])) func_dcl_list = [] if not ctx.func_dcl() else list( map(lambda func_dcl: func_dcl.accept(self), ctx.func_dcl())) return Program(var_dcl_list + func_dcl_list)
def visitExp(self, ctx: BKITParser.ProgramContext): # exp1 if (ctx.getChildCount() == 1): return ctx.exp1(0).accept(self) # exp1 INT_EQ exp1 return BinaryOp( ctx.getChild(1).getText(), ctx.exp1(0).accept(self), ctx.exp1(1).accept(self))
def visitProgram(self, ctx: BKITParser.ProgramContext): lstdecl = [] for x in range(0, ctx.getChildCount() - 1): decl = self.visit(ctx.getChild(x)) if type(decl) == type([]): lstdecl += decl else: lstdecl.append(decl) return Program(lstdecl)
def visitList_statement(self, ctx: BKITParser.ProgramContext): var_declare_list = [] statement_list = [] var_declare_list = destructure_list(list( map(lambda x: x.accept(self), ctx.var_declare()))) statement_list = list(map(lambda x: x.accept(self), ctx.statement())) return (var_declare_list, statement_list)
def visitProgram(self, ctx: BKITParser.ProgramContext): declList = [] if ctx.var_declare(): for x in ctx.var_declare(): declList.extend(self.visitVar_declare(x)) if ctx.func_declare(): for x in ctx.func_declare(): declList.extend(self.visitFunc_declare(x)) return Program(declList)
def visitProgram(self, ctx: BKITParser.ProgramContext): list_decl = [] if ctx.global_dec(): for x in ctx.global_dec(): list_decl.extend(x.accept(self)) if ctx.function_dec(): for x in ctx.function_dec(): list_decl.append(x.accept(self)) return Program(list_decl)
def visitProgram(self, ctx: BKITParser.ProgramContext): """ Return program object""" varDecls = [] for varDeclCtx in ctx.varDeclStm(): varDecls += varDeclCtx.accept(self) funcDecls = [ funcDeclCtx.accept(self) for funcDeclCtx in ctx.functionDecl() ] decls = varDecls + funcDecls return Program(decls)
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 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 visitProgram(self, ctx: BKITParser.ProgramContext): # [VarDecl(a,[1].{1,2.5})] # [VarDecl(b,[],2)] var_declare_list = [] # [FuncDecl(foo,n,x[3],([VarDecl(a,[3,1].{{1},{1},{2.5}})].))] func_declare_list = [] if (ctx.var_declare(0) != None): var_declare_list = destructure_list(list( map(lambda x: x.accept(self), ctx.var_declare()))) if (ctx.func_declare(0) != None): func_declare_list = list( map(lambda x: x.accept(self), ctx.func_declare())) return Program(var_declare_list + func_declare_list)
def visitLiteral(self, ctx: BKITParser.ProgramContext): if (ctx.INTEGER_LITERAL()): return IntLiteral(int(ctx.INTEGER_LITERAL().getText(), 0)) if (ctx.FLOAT_LITERAL()): return FloatLiteral(float(ctx.FLOAT_LITERAL().getText())) if (ctx.STRING_LITERAL()): return StringLiteral(ctx.STRING_LITERAL().getText()) if (ctx.array_literal()): return ctx.array_literal().accept(self) return ctx.bool_literal().accept(self)
def visitProgram(self, ctx: BKITParser.ProgramContext): lstdecl = [] if ctx.vardecl(): for x in ctx.vardecl(): decl = self.visit(x) if type(decl) == type([]): lstdecl = lstdecl + decl else: lstdecl.append(decl) if ctx.funcdecl(): for x in ctx.funcdecl(): decl = self.visit(x) if type(decl) == type([]): lstdecl = lstdecl + decl else: lstdecl.append(decl) return Program(lstdecl)
def visitProgram(self,ctx:BKITParser.ProgramContext): mainList = [] for x in ctx.main(): mainCell = self.visitMain(x) if isinstance(mainCell, list): mainList.extend(mainCell if mainCell else []) else: mainList.append(mainCell) return Program(mainList)
def visitProgram(self,ctx:BKITParser.ProgramContext): varDecls = reduce(lambda acc, ele: acc + ele.accept(self), ctx.varStmt() or [], []) funcDecls = reduce(lambda acc, ele: acc + [ele.accept(self)], ctx.func() or [], []) return Program(varDecls + funcDecls)
def visitProgram(self, ctx: BKITParser.ProgramContext): return Program(ctx.many_declare().accept(self))
def visitProgram(self, ctx: BKITParser.ProgramContext): # Program([VarDecl(Id(a),IntType)]) # return 1 + ctx.vardecls().accept(self) return Program(ctx.vardecls().accept(self))
def visitProgram(self, ctx: BKITParser.ProgramContext): return Program( self.visit(ctx.list_var_decl()) + self.visit(ctx.list_func_decl()))
def visitProgram(self,ctx:BKITParser.ProgramContext): if ctx.vardecls(): return self.visitVardecls(ctx.vardecls()) + 1 if ctx.vardecls() else 1 else: return 1
def visitProgram(self, ctx: BKITParser.ProgramContext): return Program(ctx.variable_declaration_part().accept(self) + ctx.function_declaration_part().accept(self))
def visitProgram(self, ctx: BKITParser.ProgramContext): # return Program(reduce(lambda a, b: a + b.accept(self), ctx.vardecl(), [])) vardecl_list = list(map(lambda x: x.accept(self), ctx.vardecl())) return Program(flatten_list(vardecl_list))