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)
Exemplo n.º 2
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))
Exemplo n.º 3
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)
Exemplo n.º 4
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.º 5
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.º 6
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))
Exemplo n.º 7
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))
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 10
0
 def visitExp5(self, ctx: BKITParser.ProgramContext):
     # index_exp
     if (ctx.getChildCount() == 1):
         return ctx.index_exp().accept(self)
     return UnaryOp(ctx.getChild(0).getText(), ctx.exp5().accept(self))
Exemplo n.º 11
0
 def visitExp4(self, ctx: BKITParser.ProgramContext):
     if (ctx.getChildCount() == 1):
         return ctx.exp5().accept(self)
         # return UnaryOp("[]", ArrayCell(None, [IntLiteral(value=34)]))
     return UnaryOp(ctx.getChild(0).getText(), ctx.exp4().accept(self))