Not really... Hi Ivan
Right now I'm screwing around, downgrading Javascript so it looks like 80's unstructured BASIC.
Sticking this into an .html file:
<!DOCTYPE html>
<html>
<head>
<title>BASIC</title>
<meta charset="utf-8">
<style>
html, body, body * {
background: #005;
color: #db9;
font-family: Consolas, 'Lucida console', monospace, monospace;
margin: 0;
padding: 0;
font-size: 16px;
overflow-x: hidden;
scrollbar-color: #444 transparent !important;
}
#term-output {
white-space: pre-wrap;
}
#term-input {
border: none;
width: 100vw;
}
</style>
<style id="paper-style">
html, body, body * {}
</style>
</head>
<body>
<pre id="term-output"></pre><input type="text" id="term-input">
<script>
String.prototype.regexIndexOf = function(regex, startpos) {
var indexOf = this.substring(startpos || 0).search(regex);
return (indexOf >= 0) ? (indexOf + (startpos || 0)) : indexOf;
}
var BASIC = {};
var that;
BASIC.color = "#db9";
BASIC.program = {},
BASIC.progPointer = "stop",
BASIC.nextProgPointer = "stop";
BASIC.subStack = [];
const rem = function() {}
const print = function(rawtxt) {
var txt = (typeof rawtxt == "string" || typeof rawtxt == "number") ? rawtxt : JSON.stringify(rawtxt);
BASIC.termOutput.innerHTML += `\n<span style="color:${BASIC.color};">${txt}</span>`;
window.scrollTo(0,document.body.scrollHeight);
}
const pen = function(c) {
BASIC.color = c;
}
const paper = function(b) {
BASIC.paperStyle.innerHTML = `html, body, body * { background: ${b};}`;
}
const edit = function(lineNumber, instruction) {
if (typeof instruction == "undefined") {
BASIC.termInput.value = lineNumber+' '+BASIC.program[lineNumber];
} else {
BASIC.program[lineNumber] = instruction.trim();
}
}
const run = function(start) {
BASIC.progPointer = BASIC.orderedLines().filter(l => l >= (start || 0))[0];
while (BASIC.progPointer) {
BASIC.nextProgPointer = BASIC.orderedLines().filter(l => l > BASIC.progPointer)[0];
that = BASIC.execute(BASIC.program[BASIC.progPointer]);
BASIC.progPointer = BASIC.nextProgPointer;
}
BASIC.progPointer = "stop";
}
const goto = function(n) {
BASIC.nextProgPointer = BASIC.orderedLines().filter(l => l >= n)[0];
}
const gosub = function(n) {
BASIC.subStack.push(BASIC.progPointer);
BASIC.nextProgPointer = BASIC.orderedLines().filter(l => l >= n)[0];
}
const end = function(n) {
var previous = BASIC.subStack.pop();
BASIC.nextProgPointer = BASIC.orderedLines().filter(l => l > previous)[0];
}
const list = function(rawStart, rawEnd) {
var lineList = BASIC.orderedLines();
var start = rawStart || lineList[0];
var end = rawEnd || lineList[lineList.length-1];
lineList.filter(l => l >= start && l <= end).forEach(l => { print(l+' '+BASIC.program[l]); });
}
const cls = function() {
BASIC.termOutput.innerHTML = '';
}
BASIC.execute = function(rawloc) {
var result;
var loc = rawloc+' ';
try {
var verb = loc.substr(0, loc.regexIndexOf(/[ =]/));
var args = eval('['+loc.substr(verb.length)+']');
result = eval(verb).apply(null, args);
var success = true;
} catch(e) {}
if (!success) {
try{
result = eval(loc);
} catch(e) {
print((BASIC.progPointer == "stop" ? '' : `line ${BASIC.progPointer}, `) + e.message);
}
}
return result;
}
BASIC.evalInput = function(cmd) {
print(cmd);
BASIC.termInput.value = '';
var first = cmd.substr(0, cmd.indexOf(' '));
var lineNumber = parseInt(first);
if (first.length > 0 && !isNaN(lineNumber)) {
edit(lineNumber, cmd.substr(first.length));
} else {
that = BASIC.execute(cmd);
print("Ready");
BASIC.termInput.focus();
}
}
BASIC.orderedLines = function() {
return Object.keys(BASIC.program).map(t => parseInt(t)).sort((a,b)=>{a<b});
}
BASIC.termInput = document.getElementById("term-input");
BASIC.termOutput = document.getElementById("term-output");
BASIC.paperStyle = document.getElementById("paper-style");
BASIC.termInput.addEventListener("keyup", function(event) {
if (event.key === "Enter") BASIC.evalInput(BASIC.termInput.value);
});
window.onclick = function() {
BASIC.termInput.focus();
}
print("Ready");
BASIC.termInput.focus();
</script>
</body>
</html>
... you'd get an interpreter able to take a program like:
10 x = 1
20 gosub 100
30 x = x+1
40 if (x < 20) goto(20)
50 goto 200
100 print x
110 end
200 print "that's all folks"
...as I said, just screwin around.