JSFiddle - React, Tailwind, and code Playground
HTML
Program code
<textarea id=prog wrap=off></textarea>
Input (space separated)
<textarea id=inp></textarea>
<button onclick="Go()">GO</button>
<input name=Ex type=radio onclick="Ex(0)">Example 1
<input name=Ex type=radio onclick="Ex(1)">Example 2
<input name=Ex type=radio onclick="Ex(2)">Example 3
<input name=Ex type=radio onclick="Ex(3)">Example 4
<input name=Ex type=radio onclick="Ex(4)">Example 5
<br>Ouput
<textarea id=output readonly>
</textarea>
CSS
#prog {
display: block;
width: 98%;
height: 20em
}
#inp {
display: block;
width: 98%;
height: 3em;
}
#output {
display: block;
width: 98%;
height: 10em;
}
}
JavaScript
I=(c,i,k=1e5,
V=v=>v in V?V[v]:v/9 // variable getter with default initial value
)=>
(c=>{
for(p=o='';
--k&&p<c[L='length'];)
(v=(r=c[p++].split(' '))[S='shift']())? // no leading space
r[r.map(t=>w-=(m=-m)*V(t),w=0,m=1),0]?V[v]=w // Assign
:o+=v[L]&1?V(v):String.fromCharCode(V(v)&127) // Output
: // else, leading space
(v=r[S]())&&
(r[0]?r.some(t=>V(t))?0:p=9*V(v) // Goto
:(t=i[S](),V[v]=v[L]&1?t:t.charCodeAt()) // Input
)
})(c.replace(/ (?=[^9])|[^9\s]/g,'').split('\n')) // code cleaning
||o
function Go()
{
var prg=prog.value;
var input=inp.value.split(' ')
output.value = I(prg, input)
}
function Ex(e)
{
var ex=[
["", "9\n9999 \n"],
["-57 A", " 9\n9\n 99\n99\n"],
["", "999 Prints triple-nine divided by nine (111)\n\
999 9 9 Assigns triple-nine to zero (nine minus nine)\n\
999 Prints triple-nine divided by nine (0)\n\
9 999 9 Assigns single-nine to negative nine (zero minus nine)\n\
999 999 9 Adds nine to triple-nine (really subtracts negative nine)\n\
999 Prints triple-nine divided by nine (1)\n\
999 999 9 Adds nine to triple-nine (really subtracts negative nine)\n\
999 Prints triple-nine divided by nine (2)\n\
999 999 9 Adds nine to triple-nine (really subtracts negative nine)\n\
999 Prints triple-nine divided by nine (3)\n"],
["", "9 Prints single-nine divided by nine (always 1).\n\
99 9 9 Assigns double-nine to zero.\n\
99 99 Jumps to line zero (top line) if double-nine is zero.\n" ],
["", "99999999 Print G.\n\
999 99 Set triple-nine to ninety-nine.\n\
9999999999 9999999999 9999999999 99 99 9 9 999 999 Set 10-nine to zero.\n\
99999999999 9999999999 Set 11-nine to zero.\n\
\n\
\n\
\n\
\n\
\n\
999 ...