function runSimulation() { const grammar = document.getElementById("grammar").value; const inputString = document.getElementById("inputString").value; fetch("/simulate", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ grammar: grammar, input: inputString }) }) .then(res => res.json()) .then(data => { if (!data.success) { alert(data.message); return; } document.getElementById("resultBox").style.display = "block"; document.getElementById("startSymbol").innerText = data.start_symbol; document.getElementById("showInput").innerText = data.input; document.getElementById("finalResult").innerText = data.final_result; const grammarList = document.getElementById("grammarList"); grammarList.innerHTML = ""; data.grammar.forEach(rule => { const li = document.createElement("li"); li.innerText = rule; grammarList.appendChild(li); }); const exploredList = document.getElementById("exploredList"); exploredList.innerHTML = ""; data.explored.forEach(step => { const li = document.createElement("li"); li.innerText = step; exploredList.appendChild(li); }); const derivationContainer = document.getElementById("derivationContainer"); derivationContainer.innerHTML = ""; if (data.derivations.length === 0) { derivationContainer.innerHTML = "
No valid derivation found.
"; } else { data.derivations.forEach((derivation, index) => { const box = document.createElement("div"); box.className = "derivation-box"; let html = `No parse tree available.
"; } else { data.trees.forEach((tree, index) => { const box = document.createElement("div"); box.className = "tree-box"; let html = `