DKL9 GitList
Repositories
DKL9 home
rtensor
Code
Commits
Branches
Tags
Search
Tree:
1312198
Branches
Tags
master
rtensor
parser_dev.html
Import v2.3-dev from a demonic ritual
dkl9
commited
1312198
at 2023-184 18:25:57
parser_dev.html
Blame
History
Raw
<!doctype html> <html> <head> <title>Parser</title> <style> input[type=text] { width: 50vw; } </style> </head> <body> <p> <input id="ttp" type="text" /> <button id="bpb">parse</button> <button id="eeb">eval</button> <button id="pfn">postfix</button> </p> <p><label><input id="doo" type="checkbox" checked /> enable debug output (much faster when off)</label></p> <p id="mop">parse first</p> <details open><summary>debugging log</summary><p id="log"></p></details> <script src="maths_parser.js"></script> <script> function dl(t) { // when i was first testing the parser, i was getting parse times in the tens or hundreds of milliseconds // so i was wondering, is it really that slow? // no -- it's mostly because of all the debug output // if we stub this out, it goes down to 0-5 ms if (doe) { document.getElementById("log").innerHTML += t + "<br />"; } return null; } function udd(ev) { doe = ev.target.checked; } window.onerror = function(ev) { dl("ERROR: " + JSON.stringify(ev)); } const oldlog = console.log; console.error = console.debug = console.info = console.log = function(v) { oldlog(v); dl(v); }; let ast; let doe; udd({ "target": document.getElementById("doo") }); document.getElementById("bpb").onclick = function() { document.getElementById("log").innerText = ""; const lexer = new TokenStream(document.getElementById("ttp").value); dl("about to parse!"); const start = Date.now(); ast = NewParser.statement(lexer); dl(`received statement ${ast.toString()}`); const end = Date.now(); dl("parsed " + ast); document.getElementById("mop").innerText = `parsed in ${end - start} ms (token index ${lexer.tind})\n${ast.toString()}`; }; document.getElementById("eeb").onclick = function() { if (ast) { const er = ast.evaluate({}, true); dl(`evaluation result: ${er}`); document.getElementById("mop").innerText = er || "evaluation error"; } else { document.getElementById("mop").innerText += "!"; } }; document.getElementById("pfn").onclick = function() { if (ast) { document.getElementById("mop").innerText = ast.toPostfix(); } else { document.getElementById("mop").innerText += "!"; } }; document.getElementById("doo").onchange = udd; </script> </body> </html>