HTML + Javascript + jQuery + jQuery UI
Input harus diberikan di area teks dan harus diformat sebagai setiap perintah dalam satu baris. Perintah tidak peka huruf besar kecil. Semua perintah diimplementasikan sepenuhnya. Saya harap Anda menikmati.
Anda dapat mencobanya di http://jsfiddle.net/bCBfk/
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>Useless interpreter</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<style type="text/css">
textarea { height: auto; }
.badshit { color: red; }
.ui-dialog-titlebar-close { display: none; }
</style>
<script type="text/javascript">
String.prototype.startsWith = function(x) {
return this.substring(0, x.length) === x;
};
String.prototype.endsWith = function(x) {
return this.substr(this.length - x.length, x.length) === x;
};
var npe = "<pre>java.lang.NullPointerException\n"
+ " at org.esolangs.wiki.useless.memorymodel.ExistentObjectPool.findObject(ExistentObjectPool.java:684)\n"
+ " at org.esolangs.wiki.useless.interpreter.WhereInstruction.visit(WhereInstruction.java:29)\n"
+ " at org.esolangs.wiki.useless.interpreter.UselessProgram.run(UselessProgram.java:413)\n"
+ " at org.esolangs.wiki.useless.interpreter.Main.main(Main.java:53)</pre>";
var wut = navigator.userAgent + " - " + navigator.language + " - " + navigator.platform + " - Ii?".toLocaleUpperCase();
var wut2 = "";
for (var c = wut.length - 1; c >= 0; c--) {
wut2 += wut.charAt(c);
}
var popupMasterMind;
function killIt() {
clearInterval(popupMasterMind);
$(".dontuseme").remove();
popupMasterMind = null;
}
function spawn() {
var x = $("<div class='dontuseme' title=''><p></p></div>");
$("body").append(x);
x.dialog();
var bw = $("body").innerWidth();
var bh = $("body").innerHeight();
if (bh < 500) bh = 500;
var xw = x.width();
var xh = x.height();
x.parent().css({left: Math.random() * (bw - xw) + "px", top: Math.random() * (bh - xh) + "px"});
}
function dontuseme() {
if (popupMasterMind) return;
spawn();
popupMasterMind = setInterval(spawn, 700);
}
var hasOutput = false;
function clearOutput() {
$("#output").empty();
hasOutput = false;
$("#cc").hide();
}
function out(a) {
$("#output").append($(a));
hasOutput = true;
}
function finish() {
$("#running").hide();
$("#bt").show();
if (hasOutput) $("#cc").show();
}
var annoyingUser = false;
function swap() {
annoyingUser = true;
$("#everything").toggle();
setTimeout(swap, 800);
}
function randomString() {
var r = "";
var f = Math.floor(Math.random() * 12) + 8;
for (var i = 0; i < f; i++) {
r += "ABCDEFGHIJKLMNOPQRSTUVWXYZ.!?0123456789".charAt(Math.floor(Math.random() * 39));
}
return r;
}
var instructions;
function includeInstruction(name) {
name = name.toUpperCase();
if (instructions[name]) return; // Do not add it twice or overwrite existing instructions.
var array = [];
for (var e in instructions) {
array.push(e);
}
var rand = Math.floor(Math.random() * array.length);
//alert(name + ": " + array[rand]);
instructions[name] = instructions[array[rand]];
}
// DONTUSEME(n) are special cases handled elsewhere.
instructions = {
"FAIL": function() { out("<p class='badshit'>Warning: The <blink> tag is obsolete.</p>"); if (!annoyingUser) swap(); return "next"; },
"NOT": function() { out("<p class='badshit'>Warning: The NOT instruction is discouraged because it breaks yor Useless program.</p>"); return "quit"; },
"NEVER": function() { out("<pre>Wild MISSINGNO. appeared!</pre>"); return "next"; },
"IDK": function() { out("<pre>" + {}.idk + "</pre>"); return "next"; },
"BOOM!": function() { $("#everything").empty(); return "quit"; },
"KABOOM!": function() { window.location = "http://answers.yahoo.com/question/index?qid=20110816062515AANqygl"; return "quit"; },
"NO.": function() { finish(); return "quit"; },
"QWAOZAPWQFUOA": function() { out("<p class='badshit'>Sorry, I could not understand <a href='https://www.google.com.br/#q=women+psychology+and+behaviour'>this</a>.</p>"); return "next"; },
"WUT?": function() { out("<p>" + wut2 + "</p>"); return "next"; },
"WHERE?": function() { out(npe); return "next"; },
"HOW?": function() { out("<p class='badshit'>Regular expression parser failed for HTML. Cause: \"ZALGO\"</p>"); return "next"; },
"ILLEGAL": function() { out("<pre>codegolfer is not in the sudoers file. This incident will be reported</pre>"); return "next"; },
"GODEXISTS": function() { out("<p>'GOD' spelled backwards is 'DOG'. A DOG is an animal that does not exists, and by backwarding this, we conclude that GOD exists and is not an animal.</p>"); return "next"; },
"WINDOWS": function() { out("<p><img width='640' height='400' src='http://upload.wikimedia.org/wikipedia/commons/3/3b/Windows_9X_BSOD.png' alt='Sorry, this optional instruction was not implemented. Please, install the service pack.'></p>"); return "next"; },
"NOOP": function() { return "next"; },
"TURINGVSALONZO": function() {
var r = Math.random() * 10;
if (r < 2) return "next";
if (r < 7) return "t" + (Math.random() * 14 + 1) * 1000;
if (r < 9) return "t" + (Math.random() * 50 + 10) * 60 * 1000;
return "quit";
},
"42": function() {
out("<p>Calculating the answer of the life, the universe and everything.</p>");
out("<p>Estimated time is 7.5 million years.</p>");
out("<p>Don't you want to briefly take a coffe while you wait? It will not take long, I promise.</p>");
return "quit";
},
// This is special, as it needs a (surprising) useless parameter, it can't be acessed directly without prior processing, this is why it is lowercase.
"dontuseme": function() { dontuseme(); return "next"; },
// This is special. If the INCLUDE-xxx generates a INCLUDE-yyy instruction, the yyy instruction will have an unknown random generated name.
// Since yyy is random and unknown, it probably won't appear in the input source code, but implement it regardless.
"include-random": function() { includeInstruction(randomString()); return "next"; }
};
function bad(line) {
//alert(line);
out("<p class='badshit'>Syntax error: </p>");
}
function beyondEnd() {
out("<p class='badshit'>Unrecoverable error: Tried to execute code beyond the end or program.</p>");
}
function interpretInstruction(lines, idx) {
if (idx >= lines.length) { beyondEnd(); return; }
// The toUpperCase serves two purposes: Making the language case-insensitive and hiding private implementations as lowercase instructions.
ins = lines[idx].trim().toUpperCase();
var result;
// Special handling for parsing DONTUSEME(n)
if (ins.startsWith("DONTUSEME(") && ins.endsWith(")")) {
try {
parseInt(ins.substring("DONTUSEME(".length, ins.length - 1));
} catch (e) {
bad(ins);
return;
}
ins = "dontuseme";
// Special handling for INCLUDE-xxx
} else if (ins.startsWith("INCLUDE-") && ins.length > 8) {
var name = ins.substring(8);
includeInstruction(name);
ins = "NOOP"; // Already executed, follow-up as noop.
}
// Execute the instruction.
var f = instructions[ins];
if (!f) { bad(ins); return; }
var result = f();
// Move on.
if (result === "quit") return;
var toWait = result === "next" ? 0 : parseInt(result.substring(1));
var ii = idx + 1;
setTimeout(function() {
interpretInstruction(lines, ii);
}, toWait);
}
function startInterpreter() {
$("#bt").hide();
$("#cc").hide();
$("#running").show();
var src = $("#input").val();
var lines = src.split('\n');
interpretInstruction(lines, 0);
}
$(document).ready(function() {
$("#bt").click(startInterpreter);
$("#cc").click(clearOutput);
});
</script>
</head>
<body>
<div id="everything">
<p>Type here your program input:</p>
<textarea id="input" style="width: 400px; height: 150px;"></textarea>
<p>
<button id="bt">Run the program</button>
<span id="running" style="display: none;">Running the program...</span>
</p>
<p>Here is the program output:</p>
<p id="output" class="useless"></p>
<button id="cc" style="display: none;">Clear the output</button>
</div>
</body>
</html>
Ini memiliki satu perintah baru:
Ini adalah 42
perintah yang menghitung jawaban dari kehidupan, alam semesta dan segalanya. Satu-satunya kekhasan adalah bahwa dibutuhkan 7,5 juta tahun untuk menyelesaikannya.
Spoiler lainnya:
Entri ini memiliki beberapa fitur:
- Anda benar-benar akan membenci
FAIL
perintah itu.
-
BOOM!
akan mengacaukan Anda "unit eksekusi". Setidaknya windows dari DONTUSEME(n)
mampu bertahan ini.
-
KABOOM!
benar-benar berbahaya bagi dunia dalam beberapa cara buruk.
-
DONTUSEME(n)
selalu membuka jendela kosong tak terbatas yang tak bisa ditutup, masing-masing 0,8 detik. Tapi ada saklar bunuh yang tersembunyi.
-
DONTUSEME(n)
bertahan NO.
, FAIL
dan bahkan BOOM!
. Tapi aku tidak bisa bertahan hidup KABOOM!
. Alasannya adalah bahwa jendela sembulan tidak akan berfungsi karena ini bukan hasil dari klik (dan sembulan yang dibuat dengan cara lain telah lama dilarang di semua peramban utama), dan tidak dapat menggunakan iframe juga karena melanggar kebijakan yang sama-asal mula .
-
INCLUDE-xxx
dapat membuat instruksi apa saja, termasuk DONTUSEME(n)
atau INCLUDE-yyy
instruksi lain .
- Jika
INCLUDE-xxx
tidak menghasilkan INCLUDE-yyy
instruksi, yyy
nama dihasilkan secara acak. Jika Anda mengambil nama perintah yang dihasilkan dengan pembakar atau yang serupa, Anda dapat menggunakannya.
- Ini menangani sintaksis cacat dan input tidak lengkap atau kosong.