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 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 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 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 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))
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))
def visitStatement(self, ctx: BKITParser.ProgramContext): return ctx.getChild(0).accept(self)