コード例 #1
0
 def visitArray(self, ctx:GrammarParser.ArrayContext):
     tyype, cte_value, ir_register = self.visit(ctx.expression())
     if tyype != Type.INT:
         token = ctx.identifier().IDENTIFIER().getPayload()
         err("ERROR: array expression must be an integer, but it is " + str(tyype) + " in line " + str(token.line) + " and column " + str(token.column) + "\n")
         exit(-1)
     return cte_value, ir_register
コード例 #2
0
 def visitArray(self, ctx: GrammarParser.ArrayContext):
     tyype = self.visit(ctx.expression())
     if tyype != Type.INT:
         token = ctx.identifier().IDENTIFIER().getPayload()
         print("ERROR: array expression must be an integer, but it is " +
               str(tyype) + " in line " + str(token.line) + " and column " +
               str(token.column))
     return
コード例 #3
0
 def visitArray(self, ctx:GrammarParser.ArrayContext):
     # print(ctx.getText(), "ctx do visit array")
     tyype, cte_value = self.visit(ctx.expression())
     name = ctx.identifier().getText()
     #print(name)
     if tyype != Type.INT:
         token = ctx.identifier().IDENTIFIER().getPayload()
         print("ERROR: array expression must be an integer, but it is " + str(tyype) + " in line " + str(token.line) + " and column " + str(token.column))
     # print(cte_value, "print final do no visit array")
     return cte_value
コード例 #4
0
 def visitArray(self, ctx: GrammarParser.ArrayContext):
     print('Visiting a Array - second function')
     #e1[e2] onde e1 precisa ser array e e2 preisa ser inteiro, se e2 é uma cte entao val(e2) deve estar no range de type(e1)
     arrayType = self.visit(ctx.expression())
     if arrayType != Type.INT:
         text = ctx.identifier().getText()
         token = ctx.identifier().IDENTIFIER().getPayload()
         print("Erro de tipo, index do array é diferente de int" + text +
               str(token.line) + "," + str(token.column))
     #return self.visitChildren(ctx)
     return
コード例 #5
0
    def visitArray(self, ctx: GrammarParser.ArrayContext):
        #token = ctx.identifier().IDENTIFIER().getPayload()
        #print(str(token.line) + "|" + ctx.expression().getText())
        index_type = self.visit(ctx.expression())
        if index_type != Type.INT:
            token = ctx.identifier().IDENTIFIER().getPayload()
            print(
                "[ERROR]::[I tought you knew that an array index should be an INTEGER instead of <{}>.] ({},{})"
                .format(index_type, str(token.line), str(token.column)))

        return self.visitChildren(ctx)
コード例 #6
0
    def visitArray(self, ctx: GrammarParser.ArrayContext):

        expType = self.visit(ctx.expression())

        if expType != Type.INT:
            token = ctx.identifier().IDENTIFIER().getPayload()
            print(
                "ERROR: array expession must be of type int (given {}) in line {} and column {}"
                .format(expType, token.line, token.column))
            return 0
        else:
            arrayID = ctx.identifier().getText()
            self.ids_defined[arrayID] = self.ids_defined[arrayID][0], int(
                ctx.expression().getText())
            return ctx.expression()
コード例 #7
0
    def visitArray(self, ctx: GrammarParser.ArrayContext):
        array_name = ctx.identifier().getText()
        array_type = self._variable_type(array_name)
        token = ctx.identifier().IDENTIFIER().getPayload()

        if (array_type is Type.VOID):
            print(
                f"ERROR: undefined array '{array_name}' in line {token.line} and column {token.column}"
            )

        index_type = self.visit(ctx.expression())
        if index_type != Type.INT:
            print(
                f"ERROR: array expression must be an integer, but it is {index_type} in line {token.line} and column {token.column}"
            )

        return array_type