예제 #1
0
 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))
예제 #2
0
 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)
예제 #3
0
    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)
예제 #5
0
 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)
예제 #6
0
 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)
예제 #7
0
 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)
예제 #8
0
 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))
예제 #9
0
    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)
예제 #11
0
 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))
예제 #12
0
 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)
예제 #13
0
    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)
예제 #14
0
    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)
예제 #17
0
    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)
예제 #18
0
    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
예제 #19
0
 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
예제 #20
0
 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)
예제 #21
0
 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)
예제 #22
0
 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)
예제 #23
0
 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)
예제 #24
0
파일: ASTGeneration.py 프로젝트: tvhhh/bkit
 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)
예제 #25
0
 def visitProgram(self, ctx: BKITParser.ProgramContext):
     return Program(ctx.many_declare().accept(self))
예제 #26
0
파일: 3.py 프로젝트: hsonthach/PPL-201
 def visitProgram(self, ctx: BKITParser.ProgramContext):
     # Program([VarDecl(Id(a),IntType)])
     # return 1 + ctx.vardecls().accept(self)
     return Program(ctx.vardecls().accept(self))
예제 #27
0
 def visitProgram(self, ctx: BKITParser.ProgramContext):
     return Program(
         self.visit(ctx.list_var_decl()) + self.visit(ctx.list_func_decl()))
예제 #28
0
 def visitProgram(self,ctx:BKITParser.ProgramContext):
     if ctx.vardecls():
         return self.visitVardecls(ctx.vardecls()) + 1 if ctx.vardecls() else 1
     else:
         return 1
예제 #29
0
 def visitProgram(self, ctx: BKITParser.ProgramContext):
     return Program(ctx.variable_declaration_part().accept(self) +
                    ctx.function_declaration_part().accept(self))
예제 #30
0
 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))