def visitExp(self, ctx: BKITParser.ExpContext): if ctx.getChildCount() == 3: return BinaryOp( ctx.getChild(1).getText(), self.visit(ctx.getChild(0)), self.visit(ctx.getChild(2))) else: return self.visit(ctx.exp2())
def visitExp(self, ctx: BKITParser.ExpContext): # BinaryOP: if ctx.getChildCount() == 1: return self.visit(ctx.exp1(0)) else: left = self.visit(ctx.exp1(0)) right = self.visit(ctx.exp1(1)) return BinaryOp(ctx.getChild(1).getText(), left, right)
def visitExp(self, ctx:BKITParser.ExpContext): if ctx.RELATIONAL(): return BinaryOp( ctx.RELATIONAL().getText(), self.visitExp1(ctx.exp1(0)), self.visitExp1(ctx.exp1(1)) ) else: return self.visitExp1(ctx.exp1(0))
def visitExp(self, ctx: BKITParser.ExpContext): if ctx.getChildCount() == 1: #exp1 return self.visit(ctx.exp1(0)) if ctx.exp1() else None op = ctx.getChild(1).getText() left = self.visit(ctx.exp1(0)) if ctx.exp1() else None right = self.visit(ctx.exp1(1)) if ctx.exp1() else None return BinaryOp(op, left, right)
def visitExp(self, ctx: BKITParser.ExpContext): # a := b := 4 # Binary(:=,Id(a),Binary(:=,Id(b),IntLiteral(4))) # [4,b,a] terms = list(reversed(list(map(lambda x: x.accept(self), ctx.term())))) # print(terms) def binaryGen(a, b): # 4 ,b return Binary(ctx.ASSIGN(0).getText(), b, a) #print(reduce(binaryGen, terms)) return reduce(binaryGen, terms)
def visitExp(self, ctx: BKITParser.ExpContext): if ctx.getChildCount() == 1: return self.visit(ctx.exp1(0)) else: return BinaryOp(self.visit(ctx.relational()), self.visit(ctx.exp1(0)), self.visit(ctx.exp1(1)))
def visitExp(self, ctx: BKITParser.ExpContext): if ctx.getChildCount() == 1: return self.visit(ctx.operand()) elif ctx.I_SUB() or ctx.F_SUB(): return UnaryOp(ctx.getChild(0).getText(), self.visit(ctx.exp(0))) elif ctx.NOT(): return UnaryOp(ctx.NOT().getText(), self.visit(ctx.exp(0))) elif ctx.mul() or ctx.div() or ctx.I_REM(): if ctx.I_REM(): return BinaryOp(ctx.I_REM().getText(), self.visit(ctx.getChild(0)), self.visit(ctx.getChild(2))) return BinaryOp(self.visit(ctx.getChild(1)), self.visit(ctx.getChild(0)), self.visit(ctx.getChild(2))) elif ctx.add() or ctx.sub(): return BinaryOp(self.visit(ctx.getChild(1)), self.visit(ctx.getChild(0)), self.visit(ctx.getChild(2))) elif ctx.AND() or ctx.OR(): return BinaryOp( ctx.getChild(1).getText(), self.visit(ctx.getChild(0)), self.visit(ctx.getChild(2))) else: a = self.visit(ctx.getChild(1)) b = self.visit(ctx.getChild(0)) c = self.visit(ctx.getChild(2)) return BinaryOp(a, b, c)
def visitExp(self, ctx: BKITParser.ExpContext): if ctx.ASSIGN(): return Binary(ctx.ASSIGN().getText(), self.visitTerm(ctx.term()), self.visitExp(ctx.exp())) else: return self.visitTerm(ctx.term())
def visitExp(self,ctx:BKITParser.ExpContext): if ctx.ASSIGN(): return reduce(lambda rh,lh: Binary(ctx.ASSIGN(0).getText(), lh, rh), list(map(lambda term: self.visitTerm(term), ctx.term()))[::-1]) return self.visitTerm(ctx.term(0))
def visitExp(self, ctx: BKITParser.ExpContext): if ctx.getChildCount() > 1: left = self.visit(ctx.exp1()[0]) right = self.visit(ctx.exp1()[1]) if ctx.EQ(): op = str(ctx.EQ().getText()) if ctx.LTE(): op = str(ctx.LTE().getText()) if ctx.GTE(): op = str(ctx.GTE().getText()) if ctx.NEQ(): op = str(ctx.NEQ().getText()) if ctx.LT(): op = str(ctx.LT().getText()) if ctx.GT(): op = str(ctx.GT().getText()) if ctx.LTEF(): op = str(ctx.LTEF().getText()) if ctx.GTEF(): op = str(ctx.GTEF().getText()) if ctx.NEQF(): op = str(ctx.NEQF().getText()) if ctx.LTF(): op = str(ctx.LTF().getText()) if ctx.GTF(): op = str(ctx.GTF().getText()) return BinaryOp(op, left, right) else: return self.visit(ctx.exp1()[0])
def visitExp(self, ctx: BKITParser.ExpContext): # term if (ctx.getChildCount() == 1): return ctx.term().accept(self) # term ASSIGN exp return Binary(ctx.ASSIGN().getText(), ctx.term().accept(self), ctx.exp().accept(self))
def visitExp(self, ctx: BKITParser.ExpContext): if ctx.getChildCount() == 1: return self.visitChildren(ctx) elif ctx.EQ(): op = "==" elif ctx.getChild(1) == ctx.NOEQ(): op = "!=" elif ctx.getChild(1) == ctx.LESS(): op = "<" elif ctx.getChild(1) == ctx.GREAT(): op = ">" elif ctx.getChild(1) == ctx.LEEQ(): op = "<=" elif ctx.getChild(1) == ctx.GREQ(): op = ">=" elif ctx.getChild(1) == ctx.NOEQF(): op = "=/=" elif ctx.getChild(1) == ctx.LEF(): op = "<." elif ctx.getChild(1) == ctx.GRF(): op = ">." elif ctx.getChild(1) == ctx.LEQF(): op = "<=." elif ctx.getChild(1) == ctx.GEQF(): op = ">=." return BinaryOp(op, self.visit(ctx.exp()), self.visit(ctx.exp1()))
def visitExp(self,ctx:BKITParser.ExpContext): if ctx.getChildCount() == 1: return self.visit(ctx.exp1(0)) else: if ctx.ASSIGN(): return BinaryOp(ctx.ASSIGN().getText(),self.visit(ctx.exp1(0)),self.visit(ctx.exp1(1))) elif ctx.NOTEQ(): return BinaryOp(ctx.NOT_EQUAL().getText(),self.visit(ctx.exp1(0)),self.visit(ctx.exp1(1))) elif ctx.LESS_THAN(): return BinaryOp(ctx.LT().getText(),self.visit(ctx.exp1(0)),self.visit(ctx.exp1(1))) elif ctx.GREATER_THAN(): return BinaryOp(ctx.GT().getText(),self.visit(ctx.exp1(0)),self.visit(ctx.exp1(1))) elif ctx.LTOE(): return BinaryOp(ctx.ASSIGN().getText(),self.visit(ctx.exp1(0)),self.visit(ctx.exp1(1))) elif ctx.GTOE(): return BinaryOp(ctx.GET().getText(),self.visit(ctx.exp1(0)),self.visit(ctx.exp1(1))) elif ctx.ASSIGNFLOAT(): return BinaryOp(ctx.ASSIGNFLOAT().getText(),self.visit(ctx.exp1(0)),self.visit(ctx.exp1(1))) elif ctx.LTOEFLOAT(): return BinaryOp(ctx.LETFLOAT().getText(),self.visit(ctx.exp1(0)),self.visit(ctx.exp1(1))) elif ctx.GTOEFLOAT(): return BinaryOp(ctx.GETFLOAT().getText(),self.visit(ctx.exp1(0)),self.visit(ctx.exp1(1))) elif ctx.LESS_THAN_FLOAT(): return BinaryOp(ctx.LTFLOAT().getText(),self.visit(ctx.exp1(0)),self.visit(ctx.exp1(1))) elif ctx.GREATER_THAN_FLOAT(): return BinaryOp(ctx.GTFLOAT().getText(),self.visit(ctx.exp1(0)),self.visit(ctx.exp1(1)))