function deltaNFA(q, c) { // (1|0)*00 if (q=='a' && c=='0') return 'ab' if (q=='a' && c=='1') return 'a' if (q=='b' && c=='0') return 'c' return ''; //default -- no transition } function acceptNFA(w, F='c', Q='a') { //w: input String //F: final state(s) //Q: current state(s) let i = 0, txt = Q while (i < w.length) { let c = w[i], T='' for (let q of Q) T = union(T, deltaNFA(q, c)) Q = T if (Q == '') break i++; txt += ", "+c+" -> "+Q+'\n'+Q } return intersect(Q, F).length > 0 } function deltaDFA(q, c) { // (1|0)*00 if (q=='a' && c=='0') return 'b' if ((q=='a' || q=='b' || q=='c') && c=='1') return 'a' if ((q=='b' || q=='c') && c=='0') return 'c' return ''; //default -- no transition } function acceptDFA(w, F='c', Q='a') { //w: input String //F: final state(s) //Q: current state(s) let i = 0, txt = Q while (i < w.length) { let c = w[i], T='' for (let q of Q) T = union(T, deltaDFA(q, c)) Q = T if (Q == '') break i++; txt += ", "+c+" -> "+Q+'\n'+Q } return intersect(Q, F).length > 0 } function test() { let e = /00$/ let s = "" let a = [], b = [], c = []; for (let n=1; n<final.value; n++) { let w = n.toString(2) // to binary if (e.test(w)) a.push(n); if (acceptDFA(w)) b.push(n); if (acceptNFA(w)) c.push(n);
} console.log("Result Regex: [" + a + "]") console.log("Result DFA: [" + b + "]") console.log("Result NFA: [" + c + "]") out.innerHTML = "Result Regex: [" + a + "]" + '<br>' + "Result DFA: [" + b + "]" + '<br>' + "Result NFA: [" + c + "]" }