AFND TO AFD

A transformação de uma AFND para uma AFD. Recebe o conjunto de estado, a lista para testes, e o conjunto de testes.

by Klawztro

JavaScript

var q0 = {},
    q1 = {},
    q2 = {},
    qf = {};

q0.__constructor__ = 'q0';
q0.a = [q1,q0];
q0.b = [q0];


q1.__constructor__ = 'q1';
q1.a = [q2];
//q1.b = [q1];


q2.__constructor__ = 'q2';
q2.b = [qf];

qf.__constructor__ = 'qf';
qf.final = true;

// <--------------------------------------------------------------------->
function hasObject(collection,obj,identifier) {
    var size = collection.length,
        cont = 0;
    
    for(; cont < size; cont++) {
        if (collection[cont][identifier] === obj[identifier]) {
            return true;
        }
    }
    return false;
}

/**
Verifica se em uma coleção de objetos, pelo menos um deles, tem uma propriedade setada.
@param {Object Array} collection - Array de objetos.
@param {String} property - propriedade a ser pesquisada.
*/
function collectionHasProperty(collection,property) {
    var cont = 0,
        size = collection.length;
    
    for(; cont < size; cont++) {
        if (collection[cont].hasOwnProperty(property)) {
            return true;
        }
    }
    return false;
}
// <--------------------------------------------------------------------->

/**
Recebe um array de objetos e remove os elementos repetidos.
@param {Object Array} _array - array de objetos a ser pesquisado.
@param { String } identifier - campo do objeto que serve como identificador (id, nome, valor, etc...)
*/
function arrayUnique(_array,identifier) {
    var new_array = [],
        cont = 0,
        exist_in_array = false,
        size = _array.length;

    for (; cont < size; cont++) {      
        exist_in_array = hasObject(new_array,_array[cont],identifier);
        if (exist_in_array === false) {
            new_array.push(_array[cont]);
        }
    }
    return new_array;
}
// <--------------------------------------------------------------------->

function iterate(lista_letras,estado_inicial) {
    var nova_maquina = [],
        state_name_counter = 0;
        test_list = [];

    nova_maquina[0] = { estado : ...