Skip to content

Commit 3990444

Browse files
committed
Kipple is yet another hard-to-parse language
1 parent f5bbcb7 commit 3990444

File tree

4 files changed

+152
-2
lines changed

4 files changed

+152
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ It currently supports the following:
1717
* [Hello++](https://esolangs.org/wiki/Hello%2B%2B)
1818
* [HQ9+](https://esolangs.org/wiki/HQ9%2B)
1919
* [HWorld](https://esolangs.org/wiki/HWorld)
20+
* [Kipple](https://esolangs.org/wiki/Kipple)
2021
* [<stack>](https://esolangs.org/wiki/LstackG)
2122
* [Nil](https://esolangs.org/wiki/Nil)
2223
* [No.](https://esolangs.org/wiki/No%2E)

about.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
</head>
66
<body>
77
<p>
8-
Interpret Esolangs Online 2.1.2
8+
Interpret Esolangs Online 2.1.3
99
<br />
1010
This is a webpage that interprets esoteric languages in client-side
11-
JavaScript. Currently, this supports 36 languages.
11+
JavaScript. Currently, this supports 37 languages.
1212
<br />
1313
Here is the detailed information about the languages:
1414
</p>
@@ -193,6 +193,16 @@
193193
</td>
194194
<td><a href="hworld.js">hworld.js</a></td>
195195
</tr>
196+
<tr>
197+
<td>Kipple</td>
198+
<td>Doesn't support the string preprocessor</td>
199+
<td>
200+
<a href="https://esolangs.org/wiki/Kipple"
201+
>https://esolangs.org/wiki/Kipple</a
202+
>
203+
</td>
204+
<td><a href="kipple.js">kipple.js</a></td>
205+
</tr>
196206
<tr>
197207
<td>&lt;stack&gt;</td>
198208
<td>

index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ <h3>Welcome to Interpret Esolangs Online</h3>
2525
<script defer src="hellopp.js"></script>
2626
<script defer src="hq9p.js"></script>
2727
<script defer src="hworld.js"></script>
28+
<script defer src="kipple.js"></script>
2829
<script defer src="lstackg.js"></script>
2930
<script defer src="nil.js"></script>
3031
<script defer src="no.js"></script>
@@ -62,6 +63,7 @@ <h3>Welcome to Interpret Esolangs Online</h3>
6263
<option>Hello++</option>
6364
<option>HQ9+</option>
6465
<option>HWorld</option>
66+
<option>Kipple</option>
6567
<option>&lt;stack&gt;</option>
6668
<option>Nil</option>
6769
<option>No.</option>
@@ -108,6 +110,7 @@ <h3>Welcome to Interpret Esolangs Online</h3>
108110
funcs["Hello++"] = hellopp;
109111
funcs["HQ9+"] = hq9p;
110112
funcs["HWorld"] = hworld;
113+
funcs["Kipple"] = kipple;
111114
funcs["<stack>"] = lstackg;
112115
funcs["Nil"] = nil;
113116
funcs["No."] = no;

kipple.js

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
var stacks = {};
2+
function pushstack(st, v) {
3+
v &= 4294967295;
4+
if (st == "@") {
5+
if (v == 0) {
6+
stacks[st].push(48);
7+
} else {
8+
if (v & 2147483648) {
9+
for (let i of (v & 2147483647) - 2147483648 + "") {
10+
stacks[st].push(i.charCodeAt(0));
11+
}
12+
} else {
13+
for (let i of v + "") {
14+
stacks[st].push(i.charCodeAt(0));
15+
}
16+
}
17+
}
18+
} else {
19+
stacks[st].push(v);
20+
}
21+
}
22+
function topstack(st) {
23+
if (stacks[st].length) {
24+
return stacks[st][stacks[st].length - 1];
25+
}
26+
return 0;
27+
}
28+
function popstack(st) {
29+
if (stacks[st].length) {
30+
return stacks[st].pop();
31+
}
32+
return 0;
33+
}
34+
function kipple_helper(program, input, recur) {
35+
program += " ";
36+
if (!recur) {
37+
for (let i of "qwertyuiopasdfghjklzxcvbnm@") {
38+
stacks[i] = [];
39+
}
40+
for (let i of input) {
41+
stacks["i"].push(i.charCodeAt(0));
42+
}
43+
}
44+
while (program) {
45+
if (program[0] == "(") {
46+
program = program.slice(1);
47+
var p = 1;
48+
var i = 0;
49+
var fb = "";
50+
for (; i < program.length; i++) {
51+
if (program[i] == "(") {
52+
p++;
53+
} else if (program[i] == ")") {
54+
p--;
55+
}
56+
if (!p) {
57+
break;
58+
}
59+
fb += program[i];
60+
}
61+
program = program.slice(i + 1);
62+
while (stacks[fb[0]].length) {
63+
kipple_helper(fb, "", 1);
64+
}
65+
} else if (" \n\t\r\v".includes(program[0])) {
66+
program = program.slice(1);
67+
} else {
68+
var cmds = "";
69+
while (!"() \n\t\r\v".includes(program[0])) {
70+
cmds += program[0];
71+
program = program.slice(1);
72+
}
73+
while (cmds) {
74+
var cmd = "";
75+
while (cmds.length && !"><+-?".includes(cmds[0])) {
76+
cmd += cmds[0];
77+
cmds = cmds.slice(1);
78+
}
79+
cmd += cmds[0];
80+
cmds = cmds.slice(1);
81+
var tcmds = cmds;
82+
while (tcmds.length && !"><+-?".includes(tcmds[0])) {
83+
cmd += tcmds[0];
84+
tcmds = tcmds.slice(1);
85+
}
86+
if (cmd.includes(">")) {
87+
var lf = cmd.slice(0, cmd.indexOf(">")),
88+
rg = cmd.slice(cmd.indexOf(">") + 1);
89+
if ("0123456789".includes(lf[0])) {
90+
pushstack(rg, parseInt(lf));
91+
} else {
92+
pushstack(rg, popstack(lf));
93+
}
94+
} else if (cmd.includes("<")) {
95+
var lf = cmd.slice(0, cmd.indexOf("<")),
96+
rg = cmd.slice(cmd.indexOf("<") + 1);
97+
if ("0123456789".includes(rg[0])) {
98+
pushstack(lf, parseInt(rg));
99+
} else {
100+
pushstack(lf, popstack(rg));
101+
}
102+
} else if (cmd.includes("+")) {
103+
var lf = cmd.slice(0, cmd.indexOf("+")),
104+
rg = cmd.slice(cmd.indexOf("+") + 1);
105+
if ("0123456789".includes(rg[0])) {
106+
pushstack(lf, topstack(lf) + parseInt(rg));
107+
} else {
108+
pushstack(lf, topstack(lf) + popstack(rg));
109+
}
110+
} else if (cmd.includes("-")) {
111+
var lf = cmd.slice(0, cmd.indexOf("-")),
112+
rg = cmd.slice(cmd.indexOf("-") + 1);
113+
if ("0123456789".includes(rg[0])) {
114+
pushstack(lf, topstack(lf) - parseInt(rg));
115+
} else {
116+
pushstack(lf, topstack(lf) - popstack(rg));
117+
}
118+
} else if (cmd.includes("?")) {
119+
if (!topstack(cmd.slice(0, cmd.length - 1)))
120+
stacks[cmd.slice(0, cmd.length - 1)] = [];
121+
}
122+
}
123+
}
124+
}
125+
if (recur) {
126+
return;
127+
}
128+
var output = "";
129+
while (stacks["o"].length) {
130+
output += String.fromCharCode(stacks["o"].pop());
131+
}
132+
return output;
133+
}
134+
function kipple(program, input) {
135+
return kipple_helper(program, input, 0);
136+
}

0 commit comments

Comments
 (0)