HTML + Javascript + jQuery + jQuery UI
入力はテキスト領域で指定し、各コマンドを1行にフォーマットする必要があります。コマンドは大文字と小文字を区別しません。すべてのコマンドが完全に実装されました。楽しんでください。
あなたは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>
新しいコマンドが1つあります。
42
生命、宇宙、すべての答えを計算するコマンドです。唯一の癖は、完了までに750万年かかることです。
その他のネタバレ:
このエントリにはいくつかの機能があります。
- あなたは本当に
FAIL
コマンドを嫌います。
-
BOOM!
「実行ユニット」を台無しにします。少なくともからのウィンドウDONTUSEME(n)
はこれを乗り切ることができます。
-
KABOOM!
いくつかの悪い点で世界にとって本当に危険です。
-
DONTUSEME(n)
閉じられない無限の空のウィンドウを常に0.8秒ずつ開きます。ただし、非表示のキルスイッチがあります。
-
DONTUSEME(n)
生き残りNO.
、FAIL
さらにはBOOM!
。ただ生き残らせることができなかっKABOOM!
た。これは、クリックの結果ではないためポップアップウィンドウが機能せず(また、他の方法で作成されたポップアップはすべての主要なブラウザーで長い間禁止されているため)、同じオリジンポリシーに違反しているためiframeも使用できなかったためです。
-
INCLUDE-xxx
DONTUSEME(n)
またはを含む任意の命令を作成できますINCLUDE-yyy
命令。
INCLUDE-xxx
がINCLUDE-yyy
命令を生成する場合、yyy
名前はランダムに生成されます。生成されたコマンドの名前をfirebugなどで取得した場合、それを使用できます。
- 不正な構文と不完全または空の入力を処理します。