Example #1
0
 def visitDoWhileStatement(self, ctx: gmarParser.DoWhileStatementContext):
     dwhile_type = self.visit(ctx.getChild(4))
     if dwhile_type.type != BOOLEAN:
         print("Do-while arg is not boolean.")
         return None
     self.visit(ctx.getChild(4))
     return Record("do_while", BOOLEAN)
Example #2
0
    def visitSumExpression(self, ctx: gmarParser.SumExpressionContext):
        ltype = self.visit(ctx.getChild(0))
        sym = str(ctx.getChild(1))
        rtype = self.visit(ctx.getChild(2))

        if ltype is None or rtype is None or sym is None:
            print("null on addition")
            return None

        if ltype.type == STRING or ltype == CHAR:
            if rtype == STRING or rtype == CHAR:
                return Record("StringAdd", STRING)
        else:
            if ltype.type == INT and rtype.type == INT:
                return Record("intAdd", INT)

        print("type error on addition")
        return None
Example #3
0
    def visitNotEqualExpression(self, ctx:gmarParser.NotEqualExpressionContext):
        ltype = self.visit(ctx.getChild(0))
        rtype = self.visit(ctx.getChild(2))

        if ltype is None or rtype is None:
            print("None on \neq expression")
            return None
        if ltype.type == INT:
            if rtype.type == INT:
                return Record("not_equals", BOOLEAN)
            print("Compare same types")
            return None
        elif ltype.type == CHAR:
            if rtype == CHAR:
                return Record("not_equals", BOOLEAN)
            print("Compare same types")
            return None

        print("Error on \\neq expression")
        return None
Example #4
0
    def visitWhileStatement(self, ctx: gmarParser.WhileStatementContext):
        while_type = self.visit(ctx.getChild(2))
        if while_type is None:
            print("NULL of while expr.")
            return None
        elif while_type.type != BOOLEAN:
            print("While args needs to be boolean.")
            return None
        self.visit(ctx.getChild(4))

        return Record("while", BOOLEAN)
Example #5
0
    def visitLtExpression(self, ctx:gmarParser.LtExpressionContext):
        ltype = self.visit(ctx.getChild(0))
        rtype = self.visit(ctx.getChild(2))

        if ltype is None or rtype is None:
            print("None on \lt expression")
            return None
        if ltype.type == INT:
            if rtype.type == INT:
                return Record("less_than", BOOLEAN)
            print("Evaluate INT or CHARs")
            return None
        elif ltype.type == CHAR:
            if rtype == CHAR:
                return Record("less_than", BOOLEAN)
            print("Evaluate INT or CHARs")
            return None

        print("Erro on \lt expression")
        return None
Example #6
0
    def visitIfStatement(self, ctx: gmarParser.IfStatementContext):
        iftype = self.visit(ctx.getChild(2))
        if iftype is None:
            print("if statement error.")
            return None
        if iftype.type != BOOLEAN:
            print("if statement arg is not boolean.")
            return None

        self.visit(ctx.getChild(4))

        return Record("if", BOOLEAN)
Example #7
0
    def visitDivExpression(self, ctx:gmarParser.DivExpressionContext):
        ltype = self.visit(ctx.getChild(0))
        sym = str(ctx.getChild(1))
        rtype = self.visit(ctx.getChild(2))

        if ltype is None or rtype is None or sym is None:
            print("null on division")
            return None
        if ltype.type == INT and rtype.type == INT:
            return Record("int arithmetic", INT)

        print("type error on division")
        return None
Example #8
0
    def visitConjunctionExpression(self, ctx:gmarParser.ConjunctionExpressionContext):
        ltype = self.visit(ctx.getChild(0))
        rtype = self.visit(ctx.getChild(2))

        if ltype is None or rtype is None:
            print("Null on logical expr")
            return None
        if ltype.type == BOOLEAN:
            if rtype.type == BOOLEAN:
                return Record("logical", BOOLEAN)
            print("type different from boolean on a logical expression")
            return None
        print("error on logical expression")
        return None
Example #9
0
    def visitArraySelectExpression(self, ctx: gmarParser.ArraySelectExpressionContext):
        ltype = self.visit(ctx.getChild(0)) # int_arr
        rtype = self.visit(ctx.getChild(2)) # int

        if ltype is None:
            print("array error")
            return None
        if rtype is None:
            print("array index error")
            return None

        if ltype.type != INT_ARRAY:
            print("argument is no an int array")
            return None
        if rtype.type != INT:
            print("array index can only be an integer")
            return None
        return Record("int_array", INT)
Example #10
0
 def visitBoolean(self, ctx: gmarParser.BooleanContext):
     return Record('char', CHAR)
Example #11
0
 def visitArrayLengthExpression(self, ctx: gmarParser.ArrayLengthExpressionContext):
     tp = self.visit(ctx.getChild(0))
     if tp.type != INT_ARRAY:
         print("Length can be called on int arrays")
         return None
     return Record("arrayLength", INT)
Example #12
0
 def visitIntegerExpression(self, ctx: gmarParser.IntegerExpressionContext):
     return Record("int", INT)
Example #13
0
 def visitArrayCreateExpression(self, ctx: gmarParser.ArrayCreateExpressionContext):
     tr = self.visit(ctx.getChild(3))
     if tr.type != INT:
         print("array size must be an integer")
         return None
     return Record("int_array", INT_ARRAY)
Example #14
0
 def visitMinusExpression(self, ctx: gmarParser.MinusExpressionContext):
     typeRec = self.visit(ctx.getChild(1))
     if typeRec.type != INT:
         print("Minus operator can preceen int value")
         return None
     return Record("minusInt", INT)