コード例 #1
0
 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())
コード例 #2
0
ファイル: ASTGeneration.py プロジェクト: negordyh/PPL_BKIT
 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):
     # 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)
コード例 #4
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)
コード例 #5
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)