Prelude interpreter
JavaScript interpreter for the esoteric programming language Prelude: http://esolangs.org/wiki/Prelude
by Martin BĂĽttner
HTML
<div style="font-size:12px;font-family:Verdana, Geneva, sans-serif;">Code:
<br>
<textarea id="code" rows="4" style="overflow:scroll;overflow-x:hidden;width:90%;">1( #^ #^^ (#^+!
6 9+ 05+5+^#^+! #^ ^+!
(((1- )#^##)^^+ )7-!)1433545514232323344949145353495314235494040404232323013334492349532333344953493435343584233475234501333449530423232349495323232323495323230494)</textarea>
<br>Input:
<br>
<textarea id="input" rows="2" style="overflow:scroll;overflow-x:hidden;width:90%;">5a-13 11 2e3</textarea>
<p>Numeric Input:
<input id="num_input" type="checkbox"> Numeric Output:
<input id="num_output" type="checkbox"> Timeout:
<input id="timeout" type="checkbox" checked="checked">
<br>
<br>
<input id="run" type="button" value="Run" onclick="run()">
<input id="stop" type="button" value="Stop" onclick="interrupt()" disabled="disabled">
<input id="clear" type="button" value="Clear" onclick="clear_output()"> <span id="stderr" style="color:red"></span>
</p>Output:
<br>
<textarea id="output" rows="6" style="overflow:scroll;width:90%;"></textarea>
</div>
JavaScript
var ITERS_PER_SEC = 100000;
var TIMEOUT_MILLISECS = 5000;
var ERROR_LOOP_MISMATCH = "Mismatched parentheses";
var ERROR_LOOP_MULTI = "Multiple parentheses in the same column";
var ERROR_TIMEOUT = "Timeout";
var ERROR_INTERRUPT = "Interrupted by user";
var code, input, timeout, num_input, num_output, loop_stack, loop_map;
var running, start_time, code_ptr, width, input_ptr, voices, iterations;
function clear_output() {
document.getElementById("output").value = "";
document.getElementById("stderr").innerHTML = "";
}
function stop() {
running = false;
document.getElementById("run").disabled = false;
document.getElementById("stop").disabled = true;
document.getElementById("clear").disabled = false;
document.getElementById("num_input").disabled = false;
document.getElementById("num_output").disabled = false;
document.getElementById("timeout").disabled = false;
}
function interrupt() {
error(ERROR_INTERRUPT);
}
function error(msg) {
document.getElementById("stderr").innerHTML = msg;
stop();
}
function run() {
clear_output();
document.getElementById("run").disabled = true;
document.getElementById("stop").disabled = false;
document.getElementById("clear").disabled = true;
document.getElementById("num_input").disabled = false;
document.getElementById("num_output").disabled = false;
document.getElementById("timeout").disabled = false;
code = document.getElementById("code").value;
input = document.getElementById("input").value;
num_input = document.getElementById("num_input").checked;
num_output = document.getElementById("num_output").checked;
timeout = document.getElementById("timeout").checked;
loop_stack = [];
loop_map = {};
if (num_input) {
input = input.match(/-?\d+/g).map(function (n) {
return +n;
});
} else {
input = input.split("").map(function (s) {
return s.charCodeAt(0);
});
}
...