lambdaway
::
sweet_little_language
3
|
list
|
login
|
load
|
|
_h1 sweet little language {center See a better approach in [[story]] and [[story2]]} _p Following [[http://ward.asia.wiki.org/view/sweet-little-language| http://ward.asia.wiki.org/view/sweet-little-language]]. _p Edit the text field below then click on the {b RUN} button to display the text in red color. {div {@ id="lt_input" contenteditable style="border:1px solid #888; padding:5px;"} Hello World} {input {@ type="button" value="RUN" onclick="document.getElementById('lt_output').innerHTML += ' {br} ' + document.getElementById('lt_input').innerHTML"}} {div {@ id="lt_output" style="border:1px solid #888; padding:5px; color:#f00"}...} _h2 code {pre °° {div {@ id = "lt_input" contenteditable style = "border:1px solid #888; padding:5px;" } Hello World } {input {@ type = "button" value = "RUN" onclick = "document.getElementById('lt_output').innerHTML += ' {br} ' + document.getElementById('lt_input').innerHTML"}} {div {@ id = "lt_output" style = "border:1px solid #888; padding:5px; color:#f00" } ... } °°} {hr} _h2 from [[sweet-little-language|http://ward.asia.wiki.org/view/sweet-little-language]] _p This is the ward's v2.html version, slightly adapted to the wiki, lambdatank. Open the page_editor to read the code. {h1 Sweet Little Interpreter} {div {@ class="program"} {pre {@ id="program" contenteditable="true"}Hello World}} {div {@ class="buttons"} {input {@ type="button" value="Run" onclick="run()"}}} {div {@ class="output"} {pre {@ id="trace"}} {pre {@ id="output"}}} {script // commented to avoid conflicts with lamdatank // Save program in local storage between reloads let version = location.pathname.split('/').pop() if (localStorage[version]) program.innerText = localStorage[version] program.addEventListener('focusout', event => { localStorage[version] = program.innerText }) // Parse and execute the program, display output function run () { execute(parse(program.innerText)) } function parse (text) { return text.split(/\n+/).map(line => line.split(/\s+/)) } function execute (code) { for (let line of code) { for (let word of line) { output.innerText += word + ' ' } output.innerText += "\n" } } } ;; end script
lambdaway v.20211111