Add Malbolge interpreter
This commit is contained in:
parent
8148c1a8a8
commit
1d6917f2aa
5
package-lock.json
generated
5
package-lock.json
generated
@ -8172,6 +8172,11 @@
|
|||||||
"pify": "^3.0.0"
|
"pify": "^3.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"malbolge-vm": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/malbolge-vm/-/malbolge-vm-1.0.2.tgz",
|
||||||
|
"integrity": "sha1-AXFAPb2Js4qi10yUzalcqRGo9ms="
|
||||||
|
},
|
||||||
"map-age-cleaner": {
|
"map-age-cleaner": {
|
||||||
"version": "0.1.3",
|
"version": "0.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz",
|
||||||
|
|||||||
@ -113,6 +113,7 @@
|
|||||||
"lodash": "^4.17.11",
|
"lodash": "^4.17.11",
|
||||||
"loglevel": "^1.6.1",
|
"loglevel": "^1.6.1",
|
||||||
"loglevel-message-prefix": "^3.0.0",
|
"loglevel-message-prefix": "^3.0.0",
|
||||||
|
"malbolge-vm": "^1.0.2",
|
||||||
"moment": "^2.23.0",
|
"moment": "^2.23.0",
|
||||||
"moment-timezone": "^0.5.23",
|
"moment-timezone": "^0.5.23",
|
||||||
"ngeohash": "^0.6.3",
|
"ngeohash": "^0.6.3",
|
||||||
|
|||||||
@ -395,5 +395,11 @@
|
|||||||
"Return",
|
"Return",
|
||||||
"Comment"
|
"Comment"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Esoteric Programming",
|
||||||
|
"ops": [
|
||||||
|
"Malbolge"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
88
src/core/operations/Malbolge.mjs
Normal file
88
src/core/operations/Malbolge.mjs
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/**
|
||||||
|
* @author kassi [kassi@noreply.com]
|
||||||
|
* @copyright KS 2018
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from '../Operation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Malbolge operation
|
||||||
|
*/
|
||||||
|
class Malbolge extends Operation {
|
||||||
|
/**
|
||||||
|
* Malbolge constructor
|
||||||
|
*/
|
||||||
|
|
||||||
|
constructor () {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = 'Malbolge';
|
||||||
|
this.module = 'Default';
|
||||||
|
this.description = 'Malbolge, invented by Ben Olmstead in 1998, is an esoteric programming language designed to be as difficult to program in as possible. The first ‘Hello, world!’ program written in it was produced by a Lisp program using a local beam search of the space of all possible programs. It is modeled as a virtual machine based on ternary digits.';
|
||||||
|
this.infoURL = 'http://esolangs.org/wiki/Malbolge';
|
||||||
|
this.inputType = 'string';
|
||||||
|
this.outputType = 'string';
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
'name': 'User Input (line by line)',
|
||||||
|
'type': 'text',
|
||||||
|
'value': ''
|
||||||
|
}
|
||||||
|
];
|
||||||
|
this.patterns = [
|
||||||
|
{
|
||||||
|
match: '^(?:[\\x21-\\x7e)?$',
|
||||||
|
flags: 'i',
|
||||||
|
args: []
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {String}
|
||||||
|
*/
|
||||||
|
run (input, args) {
|
||||||
|
const [userInput] = args;
|
||||||
|
const EOF = 59048;
|
||||||
|
|
||||||
|
var mb = require('malbolge-vm'),
|
||||||
|
vm = mb.load(input),
|
||||||
|
temp,
|
||||||
|
userInputLines = userInput.split('\n'),
|
||||||
|
userInputIndex = 0,
|
||||||
|
output = '';
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
while ((temp = mb.step(vm)) !== mb.EXIT) {
|
||||||
|
if (temp !== null) { output += String.fromCharCode(temp); }
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} catch (e) {
|
||||||
|
if (e === mb.WANTS_INPUT) {
|
||||||
|
var txt;
|
||||||
|
if (userInputIndex < userInputLines.length) {
|
||||||
|
txt = userInputLines[userInputIndex];
|
||||||
|
userInputIndex++;
|
||||||
|
} else {
|
||||||
|
txt = window.prompt('User input expected', '');
|
||||||
|
}
|
||||||
|
for (var i = 0; i < txt.length; i++) {
|
||||||
|
mb.step(vm, txt.charCodeAt(i));
|
||||||
|
}
|
||||||
|
mb.step(vm, EOF);
|
||||||
|
} else {
|
||||||
|
console.log('Error: ' + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Malbolge;
|
||||||
Loading…
x
Reference in New Issue
Block a user