def visitExpressionDiferente(self, expressionDiferente):
        #print('visitExpressionDiferente')
        tipoExp1 = expressionDiferente.Expr2.accept(self)
        tipoExp2 = expressionDiferente.Expr3.accept(self)

        tipoExp1 = st.getNewType(tipoExp1)
        tipoExp2 = st.getNewType(tipoExp2)

        if (tipoExp1 not in st.TiposPrimitivos):
            tipoExp1 = st.getBindable(tipoExp1)
            if (tipoExp1 != None):
                tipoExp1 = tipoExp1[st.TYPE]

        if (tipoExp2 not in st.TiposPrimitivos):
            tipoExp2 = st.getBindable(tipoExp1)
            if (tipoExp2 != None):
                tipoExp2 = tipoExp2[st.TYPE]

        c = coercion(tipoExp1, tipoExp2)
        if (c == None):
            expressionDiferente.accept(self.printer)
            print('\n\t[Erro]: Comparação invalida. A expressao ', end='')
            expressionDiferente.Expr2.accept(self.printer)
            print(' eh do tipo', tipoExp1, 'enquanto a expressao ', end='')
            expressionDiferente.Expr3.accept(self.printer)
            print(' eh do tipo', tipoExp2,
                  'quando deveriam ser do mesmo tipo\n')
        return c
    def visitClassicVarSpec(self, classicVarSpec):
        #print('visitClassicVarSpec')
        variaveis = classicVarSpec.IdentifierList.accept(self)
        tipo = classicVarSpec.Type

        tipo = st.getNewType(tipo)
        if (tipo == None):
            classicVarSpec.accept(self.printer)
            print('\n\t[ERRO] Tipo indefinido')

        for k in range(len(variaveis)):
            if (st.getBindable(variaveis[k]) == None):
                st.addVar(variaveis[k], tipo)
            else:
                classicVarSpec.accept(self.printer)
                print('\n\t[Erro]:', variaveis[k], 'redefinida neste bloco')

        expressao = classicVarSpec.ExpressionList.accept(self)

        if (type(expressao) != type([])):
            if (expressao != tipo):
                classicVarSpec.accept(self.printer)
                print(
                    '\n\t[Erro]: Atribuicao nao compativel com o tipo declarado'
                )
        else:
            for i in range(len(expressao)):
                if (expressao[i] != tipo):
                    classicVarSpec.accept(self.printer)
                    print(
                        '\n\t[Erro]: Atribuicao nao compativel com o tipo declarado'
                    )
                    break
    def visitDefinirTipo(self, definirTipo):
        tipo = st.getNewType(definirTipo.Type)
        if (tipo == None):
            definirTipo.accept(self.printer)
            print('\n\t[ERRO] tipo de retorno indefinido')

        return [tipo]
    def visitListTypeExp(self, listTypeExp):
        #print('visitListTypeExp')
        variaveis = listTypeExp.IdentifierList.accept(self)
        tipo = st.getNewType(listTypeExp.Type)

        for indice in range(len(variaveis)):
            if (st.getBindable(variaveis[indice]) == None):
                st.addVar(variaveis[indice], tipo)
            else:
                listTypeExp.accept(self.printer)
                print('\n\t[ERRO]:', variaveis[indice],
                      'redefinida neste bloco')

        expressao = listTypeExp.ExpressionList.accept(self)

        if (type(expressao) is not list):
            if (expressao in st.TiposPrimitivos and expressao != tipo):
                listTypeExp.accept(self.printer)
                print(
                    '\n\t[ERRO]: Atribuicao nao compativel com o tipo declarado'
                )
            elif (expressao != tipo):
                expressao = st.getBindable(expressao)
                if (None == expressao or expressao[st.TYPE] != tipo):
                    listTypeExp.accept(self.printer)
                    print(
                        '\n\t[ERRO]: Atribuicao nao compativel com o tipo declarado'
                    )
        else:
            for ind in range(len(expressao)):
                if (expressao[ind] != tipo):
                    listTypeExp.accept(self.printer)
                    print('\n\t[ERRO]: Atribuicao nao compativel')
                    break
    def visitExpressionMod(self, expressionMod):
        #print('visitExpressionMod')
        tipoExp1 = expressionMod.Expr5.accept(self)
        tipoExp2 = expressionMod.Expr4.accept(self)

        tipoExp1 = st.getNewType(tipoExp1)
        tipoExp2 = st.getNewType(tipoExp2)

        c = coercion(tipoExp1, tipoExp2)
        if (c != st.INT):
            expressionMod.accept(self.printer)
            print('\n\t[Erro]: Operacao de Mod invalida. A expressao ', end='')
            expressionMod.Expr5.accept(self.printer)
            print(' eh do tipo', tipoExp1, 'enquanto a expressao ', end='')
            expressionMod.Expr4.accept(self.printer)
            print(' eh do tipo', tipoExp2, 'quando deveriam ser do tipo int\n')
        return c
    def visitExpressionDivide(self, expressionDivide):
        #print('visitExpressionDivide')
        tipoExp1 = expressionDivide.Expr5.accept(self)
        tipoExp2 = expressionDivide.Expr4.accept(self)

        tipoExp1 = st.getNewType(tipoExp1)
        tipoExp2 = st.getNewType(tipoExp2)

        c = coercion(tipoExp1, tipoExp2)
        if (c == None):
            expressionDivide.accept(self.printer)
            print('\n\t[Erro]: Divisao invalida. A expressao ', end='')
            expressionDivide.Expr5.accept(self.printer)
            print(' eh do tipo', tipoExp1, 'enquanto a expressao ', end='')
            expressionDivide.Expr4.accept(self.printer)
            print(' eh do tipo', tipoExp2, '\n')
        return c
    def visitExpressionTimes(self, expressionTimes):
        #print('visitExpressionTimes')
        tipoExp1 = expressionTimes.Expr5.accept(self)
        tipoExp2 = expressionTimes.Expr4.accept(self)

        tipoExp1 = st.getNewType(tipoExp1)
        tipoExp2 = st.getNewType(tipoExp2)

        c = coercion(tipoExp1, tipoExp2)
        if (c == None):
            expressionTimes.accept(self.printer)
            print('\n\t[Erro]: Multiplicacao invalida. A expressao ', end='')
            expressionTimes.exp1.accept(self.printer)
            print(' eh do tipo', tipoExp1, 'enquanto a expressao ', end='')
            expressionTimes.exp2.accept(self.printer)
            print(' eh do tipo', tipoExp2, '\n')
        return c
    def visitExpressionGreaterEqual(self, expressionGreaterEqual):
        #print('visitExpressionGreaterEqual')
        tipoExp1 = expressionGreaterEqual.Expr2.accept(self)
        tipoExp2 = expressionGreaterEqual.Expr3.accept(self)

        tipoExp1 = st.getNewType(tipoExp1)
        tipoExp2 = st.getNewType(tipoExp2)

        c = coercion(tipoExp1, tipoExp2)
        if (c == None):
            expressionGreaterEqual.accept(self.printer)
            print('\n\t[Erro]: Comparação invalida. A expressao ', end='')
            expressionGreaterEqual.Expr2.accept(self.printer)
            print(' eh do tipo', tipoExp1, 'enquanto a expressao ', end='')
            expressionGreaterEqual.Expr3.accept(self.printer)
            print(' eh do tipo', tipoExp2,
                  'quando deveriam ser do mesmo tipo\n')
        return c
    def visitExpressionAND(self, expressionAND):
        #print('visitExpressionAND')
        tipoExp1 = expressionAND.Expr1.accept(self)
        tipoExp2 = expressionAND.Expr2.accept(self)

        tipoExp1 = st.getNewType(tipoExp1)
        tipoExp2 = st.getNewType(tipoExp2)

        c = coercion(tipoExp1, tipoExp2)
        if (c != st.BOOL):
            expressionAND.accept(self.printer)
            print('\n\t[Erro]: Comparacao invalida. A expressao ', end='')
            expressionAND.Expr1.accept(self.printer)
            print('eh do tipo', tipoExp1, 'e a expressao ', end='')
            expressionAND.Expr2.accept(self.printer)
            print('eh do tipo', tipoExp2, 'onde ambas deveriam ser do tipo',
                  st.BOOL, '\n')
        return c
示例#10
0
    def visitSpecType(self, specType):
        #print('visitSpecType')
        identifier = specType.ID
        tipo = st.getNewType(specType.Type)

        if (tipo == None):
            specType.accept(self.printer)
            print('\n\t[ERRO] Tipo indefinido')

        st.addNewType(identifier, tipo)
示例#11
0
    def visitSpecVar(self, specVar):
        #print('visitSpecVar')
        variaveis = specVar.IdentifierList.accept(self)
        tipo = st.getNewType(specVar.Type)

        if (tipo == None):
            specVar.accept(self.printer)
            print('\n\t[ERRO] Tipo indefinido')

        for k in range(len(variaveis)):
            st.addVar(variaveis[k], tipo)
示例#12
0
    def visitParamIdDecl(self, paramIdDecl):  # ok
        listaIDs = paramIdDecl.IdentifierList.accept(self)
        tipo = st.getNewType(paramIdDecl.Type)

        if (tipo == None):
            paramIdDecl.accept(self.printer)
            print('\n\t[ERRO] Tipo indefenido')

        for k in range(len(listaIDs) + len(listaIDs)):
            if (k % 2 != 0):
                listaIDs.insert(k, tipo)

        return listaIDs