-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from MauricioDDS/main
Progress made for turing machine simulation
- Loading branch information
Showing
4 changed files
with
114 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,13 @@ | ||
import { animateNode, renderError, renderOut } from "./animateNode.js"; | ||
import { animateNode, renderError, renderOut } from "/src/animateNode.js"; | ||
import { verifyAFND } from "/src/afnd.js?t=1701900312070"; | ||
|
||
function verifyAFD(paper, graph, automata, string) { | ||
let i = 0; | ||
let state = automata.initialState; | ||
let symbol = string[i]; | ||
function verifyTM(paper, graph, machine, string) { | ||
|
||
const interval = setInterval(() => { | ||
animateNode( | ||
paper, | ||
graph, | ||
state, | ||
symbol, | ||
automata.finalStates.includes(state) | ||
); | ||
|
||
if (i >= string.length) { | ||
clearInterval(interval); | ||
|
||
if (automata.finalStates.includes(state)) { | ||
renderOut("VALID"); | ||
return; | ||
} | ||
|
||
renderOut("INVALID"); | ||
renderError("I do not end in a final state"); | ||
return; | ||
} | ||
|
||
document | ||
.querySelector("#string-out") | ||
.querySelector(`span:nth-child(${i + 1})`).className = | ||
"symbol text-blue-500 font-bold symbol-active"; | ||
|
||
const isState = automata.transitions.find( | ||
(el) => el.state === state && el.symbol.includes(symbol) | ||
); | ||
|
||
if (!isState) { | ||
clearInterval(interval); | ||
|
||
renderOut("INVALID"); | ||
return; | ||
} | ||
|
||
i++; | ||
state = isState.nextState; | ||
symbol = string[i]; | ||
}, 1000); | ||
const steps = []; | ||
|
||
verifyAFND(paper, graph, machine, string); | ||
//escribir | ||
} | ||
|
||
export { verifyAFD }; | ||
export { verifyTM }; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function createMachine() { | ||
const machine = { | ||
states: [], | ||
alphabet: [], | ||
transitions: [], | ||
moveSet: [], | ||
initialState: "", | ||
finalStates: [], | ||
}; | ||
return machine; | ||
} | ||
|
||
function clearMachine(automata) { | ||
machine.states = []; | ||
machine.alphabet = []; | ||
machine.transitions = []; | ||
moveSet = []; | ||
machine.initialState = ""; | ||
machine.finalStates = []; | ||
return machines; | ||
} | ||
|
||
function createTMTransition(automata, state, symbol, nextState) { | ||
machine.transitions.push({ state, symbol, nextState }); | ||
return machine; | ||
} | ||
|
||
export { createMachine, createTMTransition, clearMachine }; | ||
|