From 6503da59c4a88fb86b26afdc728d2810ac828213 Mon Sep 17 00:00:00 2001 From: ALESSANDRO UMBERTO DANIELE SALTARIN Date: Wed, 1 Nov 2023 22:56:00 -0500 Subject: [PATCH 1/3] Add State-transition table --- index.html | 21 ++++++++++++++ src/afd.js | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 510f1b6..7c8674e 100644 --- a/index.html +++ b/index.html @@ -130,8 +130,28 @@

Automata Simulation

Run + + +
+ + + + + + + + + + +
+ States +
+
+ + +

@@ -338,5 +358,6 @@

Collaborate

+ diff --git a/src/afd.js b/src/afd.js index 00211bc..5e4b48e 100644 --- a/src/afd.js +++ b/src/afd.js @@ -1,9 +1,17 @@ import { animateNode, renderError, renderOut } from "./animateNode.js"; +const header = document.querySelector("#table thead tr"); function verifyAFD(paper, graph, automata, string) { let i = 0; let state = automata.initialState; let symbol = string[i]; + const tableResult = document.getElementById("table"); + const principalRow = document.getElementById("body"); + const statesSaved = new Set(); + const statesIndex = new Array(); + const row = document.querySelector("tbody"); + row.innerHTML = ""; + reload(tableResult); const interval = setInterval(() => { animateNode( @@ -36,9 +44,69 @@ function verifyAFD(paper, graph, automata, string) { (el) => el.state === state && el.symbol.includes(symbol) ); + + if (symbol[0] && !statesSaved.has(isState.symbol[0])) { + + statesIndex.push(isState.symbol[0]); + const column = document.createElement("th"); + column.textContent = isState.symbol[0]; + column.classList.add("px-6", "py-3", "bg-gray-300"); + + + statesSaved.add(isState.symbol[0]); + + header.appendChild(column); + tableResult.appendChild(header); + } + + if (!statesSaved.has(isState.state)) { + statesSaved.add(isState.state); + + + const newRow = document.createElement("tr"); + const newRowState = document.createElement("th"); + newRowState.textContent = isState.state; + newRowState.classList.add( + "px-6", + "py-4", + "font-medium", + "text-gray-900", + "whitespace-nowrap" + ); + + newRow.appendChild(newRowState); + + const nextState = document.createElement("th"); + nextState.textContent = isState.nextState; + nextState.classList.add( + "px-6", + "py-4", + "font-medium", + "text-gray-900", + "whitespace-nowrap" + ); + let index = statesIndex.indexOf(isState.symbol[0]); + while (index > 0) { + const nextState = document.createElement("th"); + nextState.textContent = "{}"; + nextState.classList.add( + "px-6", + "py-4", + "font-medium", + "text-gray-900", + "whitespace-nowrap" + ); + newRow.appendChild(nextState); + index--; + } + + newRow.appendChild(nextState); + principalRow.appendChild(newRow); + tableResult.appendChild(principalRow); + } + if (!isState) { clearInterval(interval); - renderOut("INVALID"); return; } @@ -50,3 +118,14 @@ function verifyAFD(paper, graph, automata, string) { } export { verifyAFD }; + + +function reload(tableResult){ + header.innerHTML = ""; + const column = document.createElement("th"); + column.textContent = "States"; + column.classList.add("px-6", "py-3", "bg-gray-300"); + header.appendChild(column); + tableResult.appendChild(header); +}; + From 1ae6392bf20ad6243a30cfde3ac9c2833af174d7 Mon Sep 17 00:00:00 2001 From: ALESSANDRO UMBERTO DANIELE SALTARIN Date: Sun, 5 Nov 2023 23:11:24 -0500 Subject: [PATCH 2/3] Advance State-Transition table for support AFND --- src/main.js | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index fb295c7..fa23709 100644 --- a/src/main.js +++ b/src/main.js @@ -16,6 +16,7 @@ const inputLabel = document.querySelector("#input-label-name"); const inputState = document.querySelector("#input-state-name"); const btnClearAll = document.querySelector("#btn-clear-all"); const btnDownload = document.querySelector("#btn-download"); +const header = document.querySelector("#table thead tr"); const automata = createAutomata(); @@ -28,6 +29,12 @@ function run() { const string = inputString.value; const statesArr = []; const transitions = {}; + const tableResult = document.getElementById("table"); + + const principalRow = document.getElementById("body"); + const row = document.querySelector("tbody"); + const symbolIndex = new Array(); + // clear errors renderError(null); @@ -84,7 +91,103 @@ function run() { automata.finalStates = finalStates; automata.transitions = transitions; - console.log(automata); + + + + + //Transition table + row.innerHTML = ""; + reload(tableResult, header); + + //console.log(automata.alphabet); + automata.alphabet.forEach((x) => { + if(symbolIndex.indexOf(x) == -1){ + symbolIndex.push(x); + const column = document.createElement("th"); + column.textContent = x; + column.classList.add("px-6", "py-3", "bg-gray-300"); + header.appendChild(column); + tableResult.appendChild(header); + } + }); + + let index = 0; + + //Add States in a Row + //automata.states.forEach((x) => { + for(let i = 0; i < automata.states.length; i++){ + const newRow = document.createElement("tr"); + const newRowState = document.createElement("th"); + newRowState.textContent = automata.states[i]; + newRowState.classList.add( + "px-6", + "py-4", + "font-medium", + "text-gray-900", + "whitespace-nowrap" + ); + + //State in column State + newRow.appendChild(newRowState); + const infoStates = [] + + + //Get nextState + const states = Object.values(automata.transitions); + console.log(states); + let stateNumber = states[index].length; + + //Iterate States + let elements; + for(let i=0; i < stateNumber; i++){ + let info = states[index][i][0]; + let found = symbolIndex.indexOf(states[index][i][1]); + //console.log("Simbolo ", found); + if(infoStates[found]){ + infoStates[found] += "," + info; + elements = infoStates[found]; + }else{ + infoStates[found] = info; + } + } + + if(elements){automata.states.push(elements);} + console.log(automata.states); + + index++; + + infoStates.forEach((x) => { + const newRowState1 = document.createElement("th"); + newRowState1.textContent = x; + newRowState1.classList.add( + "px-6", + "py-4", + "font-medium", + "text-gray-900", + "whitespace-nowrap" + ); + + let size = infoStates.length; + let indexState = infoStates.indexOf(x); + let count = 0; + + while (size--) { + const aux = document.createElement("th"); + if(count == indexState){ + newRow.appendChild(newRowState1); + break; + }else{ + newRow.appendChild(aux); + } + count++; + } + principalRow.appendChild(newRow); + tableResult.appendChild(principalRow); + }); + // }); + } + + renderOut("Loading ..."); renderOutString(string); @@ -122,6 +225,15 @@ function changeStateName() { MicroModal.close("modal-state-name"); } +function reload(tableResult, header){ + header.innerHTML = ""; + const column = document.createElement("th"); + column.textContent = "States"; + column.classList.add("px-6", "py-3", "bg-gray-300"); + header.appendChild(column); + tableResult.appendChild(header); +}; + window.addEventListener("DOMContentLoaded", () => { MicroModal.init(); Split(["#paper", "#split-1"], { sizes: [80, 20], minSize: 300 }); From 92b65aa8f126eb7723788060a75f60932cac8aa8 Mon Sep 17 00:00:00 2001 From: ALESSANDRO UMBERTO DANIELE SALTARIN Date: Mon, 4 Dec 2023 14:32:29 -0500 Subject: [PATCH 3/3] Advance about table transition --- src/main.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main.js b/src/main.js index fa23709..a4e5ad2 100644 --- a/src/main.js +++ b/src/main.js @@ -17,7 +17,6 @@ const inputState = document.querySelector("#input-state-name"); const btnClearAll = document.querySelector("#btn-clear-all"); const btnDownload = document.querySelector("#btn-download"); const header = document.querySelector("#table thead tr"); - const automata = createAutomata(); function run() { @@ -35,6 +34,7 @@ function run() { const row = document.querySelector("tbody"); const symbolIndex = new Array(); + // clear errors renderError(null); @@ -113,6 +113,7 @@ function run() { let index = 0; + //Add States in a Row //automata.states.forEach((x) => { for(let i = 0; i < automata.states.length; i++){ @@ -134,14 +135,18 @@ function run() { //Get nextState const states = Object.values(automata.transitions); - console.log(states); + console.log(states[index], index); let stateNumber = states[index].length; //Iterate States let elements; + + for(let i=0; i < stateNumber; i++){ let info = states[index][i][0]; + console.log("Info", info); let found = symbolIndex.indexOf(states[index][i][1]); + console.log("Simbolo", states[index][i][1]); //console.log("Simbolo ", found); if(infoStates[found]){ infoStates[found] += "," + info; @@ -152,10 +157,11 @@ function run() { } if(elements){automata.states.push(elements);} - console.log(automata.states); + //console.log("Elementos", elements) index++; + let count = 0; infoStates.forEach((x) => { const newRowState1 = document.createElement("th"); newRowState1.textContent = x; @@ -169,12 +175,12 @@ function run() { let size = infoStates.length; let indexState = infoStates.indexOf(x); - let count = 0; - + console.log(x); while (size--) { const aux = document.createElement("th"); if(count == indexState){ newRow.appendChild(newRowState1); + count++; break; }else{ newRow.appendChild(aux);