Skip to content

Commit 0e274a8

Browse files
committed
Add Python code interpreting feature and ABCDXYZ
1 parent dcdd6db commit 0e274a8

File tree

9 files changed

+251
-15
lines changed

9 files changed

+251
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.bat

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Interpret Esolangs Online is a webpage that can execute esoteric languages onlin
22

33
It currently supports the following:
44
* [6](https://esolangs.org/wiki/6)
5+
* [ABCDXYZ](https://esolangs.org/wiki/ABCDXYZ)
56
* [Alphuck](https://esolangs.org/wiki/Alphuck)
67
* [APLWSI](https://esolangs.org/wiki/APLWSI)
78
* [Arithmetic](https://esolangs.org/wiki/Arithmetic)
@@ -44,3 +45,6 @@ It currently supports the following:
4445
Just click the run button!
4546

4647
You can also generate permanent links of programs. However, it you want to do that, <s>your program should **not** be too long.</s> URL length limit no longer exists!
48+
49+
### Interpreters
50+
Interpret Esolangs Online uses client-side JS to implement interpreters, but a new feature has been added in June 2025 to support the execution of Python code in client-side JS (thanks to [PyScript](https://pyscript.net)).

abcdxyz.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
var abcdxyz_py_code=`# First real interpreter for ABCDXYZ, in Python, by User:None1
2+
import sys
3+
call_stack=[]
4+
objects=[]
5+
result=''
6+
class ABCDXYZ:
7+
data=0
8+
def __init__(self,event,num):
9+
self.event,self.num=event,num
10+
def x(self,num):
11+
t=objects[num].data
12+
objects[num].data=[1,2,3,0][objects[num].data]
13+
if t==1:
14+
objects[num].fire()
15+
def y(self,num):
16+
t=objects[num].data
17+
objects[num].data=[1,2,3,0][objects[num].data]
18+
if t==2:
19+
objects[num].fire()
20+
def z(self,num):
21+
if objects[num].data:
22+
objects[num].data=[0,3,1,2][objects[num].data]
23+
def fire(self):
24+
global call_stack,result
25+
if self.num in call_stack:
26+
raise RecursionError('Recursion is forbidden')
27+
call_stack.append(self.num)
28+
for i in self.event:
29+
if i[0]=='"':
30+
if len(i)!=2 or i[1] not in '0123456789N':
31+
raise SyntaxError('" must be followed by digits or N')
32+
else:
33+
result+=('\\n' if i[1]=='N' else i[1])
34+
elif i[0]=='X':
35+
try:
36+
num=int(i[1])
37+
except:
38+
raise SyntaxError('X must be followed by a number')
39+
else:
40+
self.x(num)
41+
elif i[0]=='Y':
42+
try:
43+
num=int(i[1])
44+
except:
45+
raise SyntaxError('Y must be followed by a number')
46+
else:
47+
self.y(num)
48+
elif i[0]=='Z':
49+
try:
50+
num=int(i[1])
51+
except:
52+
raise SyntaxError('Z must be followed by a number')
53+
else:
54+
self.z(num)
55+
else:
56+
raise SyntaxError('Unknown command: {}'.format(i))
57+
call_stack.pop()
58+
n=0
59+
e=[]
60+
result=''
61+
def abcdxyz(c,inp):
62+
c=c.split()
63+
global n,e,result
64+
n=0
65+
e=[]
66+
result=''
67+
if c[0]!=str(n)+':':
68+
raise SyntaxError('Cannot find object 0')
69+
del c[0]
70+
while c:
71+
n+=1
72+
while c and c[0]!=str(n)+':':
73+
e.append(c[0])
74+
del c[0]
75+
if c:
76+
del c[0]
77+
objects.append(ABCDXYZ(e,n-1))
78+
e=[]
79+
objects[0].fire()
80+
return result`
81+
function abcdxyz(code,input){
82+
execute(abcdxyz_py_code,code,input,'abcdxyz');
83+
}

abcdxyz.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# First real interpreter for ABCDXYZ, in Python, by User:None1
2+
import sys
3+
call_stack=[]
4+
objects=[]
5+
result=''
6+
class ABCDXYZ:
7+
data=0
8+
def __init__(self,event,num):
9+
self.event,self.num=event,num
10+
def x(self,num):
11+
t=objects[num].data
12+
objects[num].data=[1,2,3,0][objects[num].data]
13+
if t==1:
14+
objects[num].fire()
15+
def y(self,num):
16+
t=objects[num].data
17+
objects[num].data=[1,2,3,0][objects[num].data]
18+
if t==2:
19+
objects[num].fire()
20+
def z(self,num):
21+
if objects[num].data:
22+
objects[num].data=[0,3,1,2][objects[num].data]
23+
def fire(self):
24+
global call_stack,result
25+
if self.num in call_stack:
26+
raise RecursionError('Recursion is forbidden')
27+
call_stack.append(self.num)
28+
for i in self.event:
29+
if i[0]=='"':
30+
if len(i)!=2 or i[1] not in '0123456789N':
31+
raise SyntaxError('" must be followed by digits or N')
32+
else:
33+
result+=('\n' if i[1]=='N' else i[1])
34+
elif i[0]=='X':
35+
try:
36+
num=int(i[1])
37+
except:
38+
raise SyntaxError('X must be followed by a number')
39+
else:
40+
self.x(num)
41+
elif i[0]=='Y':
42+
try:
43+
num=int(i[1])
44+
except:
45+
raise SyntaxError('Y must be followed by a number')
46+
else:
47+
self.y(num)
48+
elif i[0]=='Z':
49+
try:
50+
num=int(i[1])
51+
except:
52+
raise SyntaxError('Z must be followed by a number')
53+
else:
54+
self.z(num)
55+
else:
56+
raise SyntaxError('Unknown command: {}'.format(i))
57+
call_stack.pop()
58+
n=0
59+
e=[]
60+
result=''
61+
def abcdxyz(c,inp):
62+
c=c.split()
63+
global n,e,result
64+
n=0
65+
e=[]
66+
result=''
67+
if c[0]!=str(n)+':':
68+
raise SyntaxError('Cannot find object 0')
69+
del c[0]
70+
while c:
71+
n+=1
72+
while c and c[0]!=str(n)+':':
73+
e.append(c[0])
74+
del c[0]
75+
if c:
76+
del c[0]
77+
objects.append(ABCDXYZ(e,n-1))
78+
e=[]
79+
objects[0].fire()
80+
return result

about.html

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
</head>
66
<body>
77
<p>
8-
Interpret Esolangs Online 2.1.4
8+
Interpret Esolangs Online 3.0.0
99
<br />
1010
This is a webpage that interprets esoteric languages in client-side
11-
JavaScript. Currently, this supports 40 languages.
11+
JavaScript. Currently, this supports 41 languages.
12+
<br />
13+
A new feature added allows execution of Python code via <a href="https://pyscript.net"
14+
>PyScript</a
15+
>
1216
<br />
1317
Here is the detailed information about the languages:
1418
</p>
@@ -22,6 +26,16 @@
2226
</tr>
2327
</thead>
2428
<tbody>
29+
<tr>
30+
<td>ABCDXYZ</td>
31+
<td>Interpreted via Python code execution</td>
32+
<td>
33+
<a href="https://esolangs.org/wiki/ABCDXYZ"
34+
>https://esolangs.org/wiki/ABCDXYZ</a
35+
>
36+
</td>
37+
<td><a href="abcdxyz.py">abcdxyz.py</a></td>
38+
</tr>
2539
<tr>
2640
<td>Alphuck</td>
2741
<td>Supports wraps, EOF results in 0, 1000000 8-bit cells</td>

index.html

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44
<title>Interpret Esolangs Online</title>
55
</head>
66
<body>
7+
<meta charset="UTF-8">
8+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
9+
<!-- PyScript CSS -->
10+
<link rel="stylesheet" href_="https://pyscript.net/releases/2025.5.1/core.css" id="pyscss">
11+
<!-- This script tag bootstraps PyScript -->
12+
<script type="module" src_="https://pyscript.net/releases/2025.5.1/core.js" id="pysjs"></script>
713
<h3>Welcome to Interpret Esolangs Online</h3>
814
<p>
915
Interpret Esolangs Online allows you to run programs in various esoteric
1016
languages, including brainfuck, deadfish, etc.
1117
</p>
18+
<script defer src="pyexec.js"></script>
19+
<script defer src="abcdxyz.js"></script>
1220
<script defer src="alphuck.js"></script>
1321
<script defer src="aplwsi.js"></script>
1422
<script defer src="arithmetic.js"></script>
@@ -49,8 +57,11 @@ <h3>Welcome to Interpret Esolangs Online</h3>
4957
<script defer src="wte_teplw.js"></script>
5058
<script defer src="wizzcake.js"></script>
5159
<script defer src="wizzcakep.js"></script>
60+
<code id="pysout" style="display:none"></code>
61+
<code id="pyserr" style="display:none"></code>
5262
<select id="lang">
5363
<option>6</option>
64+
<option>ABCDXYZ</option>
5465
<option>Alphuck</option>
5566
<option>APLWSI</option>
5667
<option>Arithmetic</option>
@@ -102,6 +113,7 @@ <h3>Welcome to Interpret Esolangs Online</h3>
102113
var input = document.getElementById("input").value;
103114
funcs["\u203a*&\u00ab&^"] = galax;
104115
funcs["6"] = six;
116+
funcs["ABCDXYZ"] = abcdxyz;
105117
funcs["Alphuck"] = alphuck;
106118
funcs["APLWSI"] = aplwsi;
107119
funcs["Arithmetic"] = arithmetic;
@@ -145,23 +157,26 @@ <h3>Welcome to Interpret Esolangs Online</h3>
145157
var func = funcs[langname];
146158
document.getElementById("log").value = "";
147159
const s = new Date().getTime();
148-
var erroc = false;
160+
var erroc = false,f=false;
149161
try {
150162
var output = func(code, input);
163+
if(output===undefined)f=true;
151164
} catch (err) {
152165
document.getElementById("log").value = err.message + "\n";
153166
erroc = true;
154167
}
155168
const e = new Date().getTime();
156-
if (erroc) {
157-
document.getElementById("log").value =
158-
document.getElementById("log").value +
159-
`Program terminates in ${e - s} ms and raises an error.`;
160-
} else {
161-
document.getElementById("log").value =
162-
document.getElementById("log").value +
163-
`Program terminates in ${e - s} ms successfully.`;
164-
document.getElementById("output").value = output;
169+
if(!f){
170+
if (erroc) {
171+
document.getElementById("log").value =
172+
document.getElementById("log").value +
173+
`Program terminates in ${e - s} ms and raises an error.`;
174+
} else {
175+
document.getElementById("log").value =
176+
document.getElementById("log").value +
177+
`Program terminates in ${e - s} ms successfully.`;
178+
document.getElementById("output").value = output;
179+
}
165180
}
166181
};
167182
window.upload = function () {

pyexec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var outredirect=`
2+
from pyscript import window, document
3+
import sys
4+
try:
5+
res=@mainfunct(window.pys_ccode,window.pys_input);
6+
except BaseException as e:
7+
window.finish(e.__class__.__name__+': '+str(e))
8+
else:
9+
window.stdout(res)
10+
window.finish()
11+
`
12+
function stdout(s){
13+
document.getElementById("output").value+=s;
14+
}
15+
function stderr(s){
16+
document.getElementById("log").value+=s;
17+
}
18+
function finish(err){
19+
if(err){
20+
stderr(err+'\n'+`Program terminates in ${new Date().getTime() - window.pys_exec_start} ms and raises an error.`);
21+
}else{
22+
stderr(`Program terminates in ${new Date().getTime() - window.pys_exec_start} ms successfully.`);
23+
}
24+
}
25+
function execute(code,ccode,input,mainfunct){
26+
window.pys_ccode=ccode;
27+
window.pys_input=input;
28+
code+=outredirect.replaceAll('@mainfunct',mainfunct);
29+
document.getElementById("output").value='';
30+
document.getElementById("log").value='';
31+
window.pys_exec_start=new Date().getTime();
32+
document.getElementById('pyscss')['href']=document.getElementById('pyscss').getAttribute('href_');
33+
document.getElementById('pysjs')['src']=document.getElementById('pysjs').getAttribute('src_');
34+
z=document.createElement('script');
35+
z['type']='py';
36+
z.textContent=code;
37+
document.body.appendChild(z);
38+
}

pyexec_example.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var yourlang_py_code=`code here`
2+
function yourlang(code,input){
3+
execute(yourlang_py_code,code,input,'yourlang');
4+
}

wee.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,4 @@ function wee(program,input){
4646
return output;
4747
}
4848
}
49-
while(1){
50-
51-
}
5249
}

0 commit comments

Comments
 (0)