Example #1
0
 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)))
Example #2
0
 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())
Example #3
0
 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))
Example #4
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))