Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
irdkwmnsb committed May 15, 2024
1 parent 3dad14c commit 64628d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/visualizers/turing-machine/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ export const TuringMachineRender = ({ curState, curEvent }: SafeRenderProps<Turi
const program = curState.program
const cy = useRef<cytoscape.Core | null>(null)
const graphRef = useRef<HTMLDivElement>(null)
if (curEvent.name === "error") {
return <div>
Error while running: {curEvent.error + ""}
</div>
}
useEffect(() => {
if (graphRef.current === null) {
return
}
cy.current = cytoscape({
container: graphRef.current,
elements: [],
Expand Down Expand Up @@ -125,6 +123,11 @@ export const TuringMachineRender = ({ curState, curEvent }: SafeRenderProps<Turi
console.log(cy.current?.elements())
}
}, [JSON.stringify(program)])
if (curEvent.name === "error") {
return <div>
Error while running: {curEvent.error + ""}
</div>
}
return <div>
{curState.machineState.description}
<br/>
Expand Down
2 changes: 1 addition & 1 deletion src/visualizers/turing-machine/turing-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const turingMachine = async (program: Readonly<string>, startTape: Readon
for(const rule of parsed.rules) {
if (state.state === rule.curState && tapeCopy.get(state.curPosition) === rule.curTape) {
if (matchingRule !== null) {
throw new Error("Two rules match this state.")
throw new Error(`Two rules match state ${state.state} by symbol ${rule.curTape}: ${matchingRule} and ${rule}.`)
}
matchingRule = rule
}
Expand Down

0 comments on commit 64628d6

Please sign in to comment.