JSFiddle - React, Tailwind, and code Playground
by Kenny Lau
HTML
A javascript implementation of <a href="https://esolangs.org/wiki/Gaot%2B%2B">Gaot++</a>.
<br /><br />
Compressed code is also accepted. No whitespace is needed.
<br /><br />
Compressor: <a href="http://retina.tryitonline.net/#code=Ymw_KGF8ZSkrdD8KJCMxJDEKW15cZGFlXQo&input=YmFhYSBibGVlZXQ">link</a>,
decompressor: <a href="http://retina.tryitonline.net/#code=XGQrYQpiJCYkKmEKXGQrZQpibCQmJCpldApcQmIKIGI&input=M2EzZQ">link</a>,
<br /><br />
Code: <textarea id=code oninput=process() style="width:100%" rows="12">73a 13e 10e 30a 2e 13e 10e 8a 2e 13e 10e 13e 10e 4a 2e 10e 45a 13e 13e 10e 33a 10e 2e 2a 3e 13e 10e 14a 2e 13e 9a 2e 13e 4a 2e 13e 10e 4a 2e 10e 10e 10e 34a 10e</textarea>
<br /><br />
Input: <textarea id=input oninput=process() style="width:100%"></textarea>
<br /><br />
Output: <textarea id=output readonly style="background:#B4B4B4; border:0px; width:100%" rows=20>Hello, World!</textarea>
JavaScript
window.process=()=>{
var code = document.getElementById("code").value
var input = document.getElementById("input").value
var output = ""
var stack = []
var instructions = []
var pointer = 0
if(/\d/.test(code)){
//compressed
var re = /(\d+)(a|e)/g
var m = ""
while(m = re.exec(code)){
instructions.push(m[2]=="e"?-m[1]:m[1]-1)
}
}else{
//not compressed
var re = /b(a+)|bl(e+)t/g
var m = ""
while(m = re.exec(code)){
if(m[1]){
instructions.push(m[1].length-1)
}else{
instructions.push(-m[2].length)
}
}
}
var direction = 1
var iterations = 0
while(pointer >= 0 && pointer < instructions.length){
iterations++
var temp = instructions[pointer]
if(temp >= 0){
stack.push(temp)
}else{
switch(-temp){
case 2: stack.push(stack.pop()+stack.pop()); break;
case 3: stack.push(-stack.pop()+stack.pop()); break;
case 4: pointer += direction; break;
case 5: pointer = -2; break;
case 6: direction = -direction; break;
case 7: pointer += !!stack.pop() ? direction : 0; break;
case 8: pointer += !!stack.pop() ? 0 : direction; break;
case 9: output += stack.pop()+"\n"; break;
case 10: output += String.fromCharCode(stack.pop()); break;
case 11:
match = /\-?\d+/.exec(input)
stack.push(~~match[0])
input = input.substring(match.index+match.length+1)
break;
case 12: stack.push(input.codePointAt(0)); input = input.substring(1); break;
case 13: var temp = stack.pop(); stack.push(temp); stack.push(temp); break;
case 14: var a=stack.pop(),b=stack.pop(); stack.push(a); stack.push(b); break;
case 15: stack = stack.reverse(); break;
case 16: stack.push(stack[stack.length-1]); stack = stack.slice(0,-1); break;
}
}
pointer += direction;
if(iterations>=10000) break;
}
document.getElementById("output").value = output
}