예제 #1
0
    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)
예제 #2
0
 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()))
예제 #3
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())
예제 #4
0
파일: 4.py 프로젝트: hsonthach/PPL-201
 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))