Skip to content

Commit dcdd6db

Browse files
committed
Add support for Poetic
1 parent 1fd6dc3 commit dcdd6db

File tree

4 files changed

+153
-3
lines changed

4 files changed

+153
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ It currently supports the following:
2828
* [PlusIntOutput](https://esolangs.org/wiki/PlusIntOutput)
2929
* [PlusOrMinus](https://esolangs.org/wiki/PlusOrMinus)
3030
* [PlusOrOutput](https://esolangs.org/wiki/PlusOrOutput)
31+
* [Poetic](https://esolangs.org/wiki/Poetic)
3132
* [Quine.](https://esolangs.org/wiki/Quine_(programming_language))
3233
* [Random Brainfuck](https://esolangs.org/wiki/Random_Brainfuck)
3334
* [ReverseFuck](https://esolangs.org/wiki/ReverseFuck)

about.html

Lines changed: 11 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.3
8+
Interpret Esolangs Online 2.1.4
99
<br />
1010
This is a webpage that interprets esoteric languages in client-side
11-
JavaScript. Currently, this supports 39 languages.
11+
JavaScript. Currently, this supports 40 languages.
1212
<br />
1313
Here is the detailed information about the languages:
1414
</p>
@@ -307,6 +307,15 @@
307307
>
308308
</td>
309309
<td><a href="plusoroutput.js">plusorOutput.js</a></td>
310+
<tr>
311+
<td>Poetic</td>
312+
<td>Supports wraps, EOF results in 0, 1000000 8-bit cells</td>
313+
<td>
314+
<a href="https://esolangs.org/wiki/Poetic"
315+
>https://esolangs.org/wiki/Poetic</a
316+
>
317+
</td>
318+
<td><a href="poetic.js">poetic.js</a></td>
310319
</tr>
311320
<tr>
312321
<td>pRINT</td>

index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ <h3>Welcome to Interpret Esolangs Online</h3>
3636
<script defer src="plusorminus.js"></script>
3737
<script defer src="plusintoutput.js"></script>
3838
<script defer src="plusoroutput.js"></script>
39+
<script defer src="poetic.js"></script>
3940
<script defer src="print.js"></script>
4041
<script defer src="quine.js"></script>
4142
<script defer src="rbf.js"></script>
@@ -77,6 +78,7 @@ <h3>Welcome to Interpret Esolangs Online</h3>
7778
<option>PlusIntOutput</option>
7879
<option>PlusOrMinus</option>
7980
<option>PlusOrOutput</option>
81+
<option>Poetic</option>
8082
<option>pRINT</option>
8183
<option>Quine</option>
8284
<option>Random Brainfuck</option>
@@ -98,7 +100,7 @@ <h3>Welcome to Interpret Esolangs Online</h3>
98100
var langname = document.getElementById("lang").value;
99101
var code = document.getElementById("program").value;
100102
var input = document.getElementById("input").value;
101-
funcs["›*&«&^"] = galax;
103+
funcs["\u203a*&\u00ab&^"] = galax;
102104
funcs["6"] = six;
103105
funcs["Alphuck"] = alphuck;
104106
funcs["APLWSI"] = aplwsi;
@@ -126,6 +128,7 @@ <h3>Welcome to Interpret Esolangs Online</h3>
126128
funcs["PlusIntOutput"] = plusintoutput;
127129
funcs["PlusOrMinus"] = plusorminus;
128130
funcs["PlusOrOutput"] = plusoroutput;
131+
funcs["Poetic"] = poetic;
129132
funcs["pRINT"] = print;
130133
funcs["Quine"] = quine;
131134
funcs["Random Brainfuck"] = rbf;

poetic.js

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
function p2pf(code) {
2+
let res = '';
3+
while (code) {
4+
let p = 0;
5+
let q = 0;
6+
// Count letters in current sequence
7+
while (p < code.length && /[a-zA-Z']/.test(code[p])) {
8+
q += /[a-zA-Z]/.test(code[p]) ? 1 : 0;
9+
p++;
10+
}
11+
12+
// Convert letter count to digit
13+
if (q) {
14+
res += q === 10 ? '0' : q.toString();
15+
}
16+
17+
// Skip non-letter characters
18+
while (p < code.length && !/[a-zA-Z']/.test(code[p])) {
19+
p++;
20+
}
21+
code = code.slice(p);
22+
}
23+
24+
let r = '';
25+
const commands = ';[]+-><.,?';
26+
27+
while (res) {
28+
if ('3456'.includes(res[0])) {
29+
try {
30+
const repeatCount = parseInt(res[1]) || 10;
31+
r += commands[parseInt(res[0])].repeat(repeatCount);
32+
res = res.slice(2);
33+
} catch {
34+
break;
35+
}
36+
} else {
37+
r += commands[parseInt(res[0])];
38+
res = res.slice(1);
39+
}
40+
}
41+
42+
return r;
43+
}
44+
45+
function pf(program,input){
46+
var stack=[];
47+
var matches={};
48+
var ip=0;
49+
var tape=[];
50+
var p=0;
51+
var output='';
52+
for(let i=0;i<1000000;i++){
53+
tape.push(0);
54+
}
55+
for(var i=0;i<program.length;i++){
56+
if(program[i]=='['){
57+
stack.push(i);
58+
}
59+
if(program[i]==']'){
60+
if(stack.length==0){
61+
throw new Error('Right bracket does not match left bracket');
62+
}
63+
var mt=stack.pop();
64+
matches[mt]=i;
65+
matches[i]=mt;
66+
}
67+
}
68+
if(stack.length!=0){
69+
throw new Error('Left bracket does not match right bracket');
70+
}
71+
while(ip<program.length){
72+
if(program[ip]=='+'){
73+
tape[p]=tape[p]+1;
74+
if(tape[p]==256) tape[p]=0;
75+
ip=ip+1;
76+
}
77+
if(program[ip]=='-'){
78+
tape[p]=tape[p]-1;
79+
if(tape[p]==-1) tape[p]=255;
80+
ip=ip+1;
81+
}
82+
if(program[ip]=='>'){
83+
p=p+1;
84+
if(p>=1000000){
85+
throw new Error('Pointer overflow');
86+
}
87+
ip=ip+1;
88+
}
89+
if(program[ip]=='<'){
90+
p=p-1;
91+
if(p<0){
92+
throw new Error('Pointer underflow');
93+
}
94+
ip=ip+1;
95+
}
96+
if(program[ip]==','){
97+
if(input==''){
98+
tape[p]=0;
99+
}else{
100+
tape[p]=input.charCodeAt(0)%256;
101+
input=input.slice(1);
102+
}
103+
ip=ip+1;
104+
}
105+
if(program[ip]=='.'){
106+
output+=String.fromCharCode(tape[p]);
107+
ip=ip+1;
108+
}
109+
if(program[ip]=='['){
110+
if(tape[p]==0){
111+
ip=matches[ip];
112+
}else{
113+
ip=ip+1;
114+
}
115+
}
116+
if(program[ip]==']'){
117+
if(tape[p]!=0){
118+
ip=matches[ip];
119+
}else{
120+
ip=ip+1;
121+
}
122+
}
123+
if(program[ip]=='?'){
124+
tape[p]=Math.floor(Math.random()*256);
125+
}
126+
if(program[ip]==';'){
127+
break;
128+
}
129+
if(!('+-,.[]<>;?'.includes(program[ip]))){
130+
ip=ip+1;
131+
}
132+
}
133+
return output;
134+
}
135+
function poetic(program,input){
136+
return pf(p2pf(program),input);
137+
}

0 commit comments

Comments
 (0)