示例#1
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)
示例#2
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
示例#3
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)
示例#4
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
示例#5
0
    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)
示例#6
0
 def visitCall_stmt(self, ctx: BKITParser.ProgramContext):
     exps_list = ctx.exps_list().accept(self)
     return CallStmt(Id(ctx.ID().getText()), exps_list)
示例#7
0
 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)
示例#8
0
 def visitAssign_head(self, ctx: BKITParser.ProgramContext):
     if (ctx.ID() != None):
         return Id(ctx.ID().getText())
     return ctx.index_exp().accept(self)
示例#9
0
 def visitProgram(self, ctx: BKITParser.ProgramContext):
     return Program([VarDecl(Id(ctx.ID().getText()), [], None)])