Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
 def visitProgram(self, ctx: BKITParser.ProgramContext):
     return self.visitExp(ctx.exp())
Exemplo n.º 5
0
 def visitExps_list(self, ctx: BKITParser.ProgramContext):
     return list(map(lambda x: x.accept(self), ctx.exp()))
Exemplo n.º 6
0
 def visitReturn_stmt(self, ctx: BKITParser.ProgramContext):
     exp = None
     if (ctx.exp()):
         exp = ctx.exp().accept(self)
     return Return(exp)
Exemplo n.º 7
0
 def visitDo_while_stmt(self, ctx: BKITParser.ProgramContext):
     list_stmt = ctx.list_statement().accept(self)
     return Dowhile(list_stmt, ctx.exp().accept(self))
Exemplo n.º 8
0
 def visitWhile_stmt(self, ctx: BKITParser.ProgramContext):
     list_stmt = ctx.list_statement().accept(self)
     return While(ctx.exp().accept(self), list_stmt)
Exemplo n.º 9
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)
Exemplo n.º 10
0
 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])
Exemplo n.º 11
0
 def visitAssign_body(self, ctx: BKITParser.ProgramContext):
     return Assign(ctx.assign_head().accept(self), ctx.exp().accept(self))
Exemplo n.º 12
0
    def visitProgram(self, ctx: BKITParser.ProgramContext):

        return ctx.exp().accept(self)