Binary Forthleq Calculus

From Esolang
Jump to navigation Jump to search

Binary Forthleq Calculus is an esoteric programming language created by Kamila Szewczyk for the Esolang Reverse Engineering Contest.

Interpreter (C)

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#define nt op[op[0]++]
#define ot *sp--
#define C;break;case
typedef struct c_{struct c_*Q,*W;int E,R;}Z;long ip,_A;_B[10000];
Z _R={.E=999};Z*Y,*S,*W=&_R;FILE*in;void G(Z*p){for(;p&&p!=&_R;p=
p->W){if(--p->E)break;G(p->Q);p->Q=Y;Y=p;}}char I(){int c;while((
c=fgetc(in))!=EOF&&(c<'0'||c>'9'));return c==EOF?-1:c&1;}_P(){int
t,s=_A,b,m=0;for(;;){if((b=I())==-1){if(!m)break;}else if(b){for(
t=0;I(); )++t;_B[_A++]=1;_B[_A++]=t;break;}else if(I()){t=_A;_A+=
2;_B[t]=2;_B[t+1]=_P();m=1;}else{_B[_A++]=2+1;}}return _A-s;}main
(int _,char*v[]){long i;char*k="CVDCJBADCDCCBADCECBBAAAC";for(_A=
0;_A<24;++_A)_B[_A]=k[_A]-'A';++_A;in=fopen(v[1],"rb");_B[24]=_P(
);char o[ftell(in)];int po=0;rewind(in);Z *t,*e;for(;;)switch(_B[
ip]){C 1:e=t=W;for(int i=0;i<_B[ip+1]&&e!=&_R;++i)e=e->Q;ip=e->R;
W=(++(e->W)->E,e->W);G(t);break;C 2:if(!(t=Y)){t=calloc(1,sizeof(
Z));}Y=t->Q;t->E=1;t->R=ip+2+_B[ip+1];t->W=t->R>_B[1]&&t->R!=_A?(
++W->E,W):&_R;t->Q=S;S=t;ip+=2;C 3:if(!S){long s=0L,ind=0,c;while
(!feof(in)){c=fgetc(in);if(c==EOF)break;s+=c; if(isdigit(c))if(o[
ind++]!=(c&1))exit(1);}if(s%2!=o[ind])exit(1);rewind(in);ip=0;fth
();exit(0);}Z*t=S;S=t->Q;t->Q=W;W=t;++ip;C 0:o[po++]=ip&1;ip=2;G(
W);W=&_R;break;}}op[60000]={32},L=1,t=64,w,STK[10000],*sp=STK,top
;char s[10000];void _W(x){nt=L;L=*op-1;nt=t;nt=x;fscanf(in,"%s",s
+t);t+=strlen(s+t)+1;}exec(x){switch(op[x++]){C 5:for(w=fscanf(in
,"%s",s)<1?exit(0),0:L;strcmp(s,&s[op[w+1]]);w=op[w]);w-1?exec(w+
2):(nt=2,nt=atoi(s))C 12:ip=op[op[1]--] C 2:op[++op[1]]=ip;ip=x C
15:top=sp[-top] C 1:nt=x C 7:op[top]=ot;top=ot C 0:*++sp=top;top=
op[ip++]C 8:top=ot-top C 6:top=op[top] C 10:top=ot/top C 3:_W(1);
nt=2 C 11:top=top<=0; C 4:*op-=2;nt=2; C 13:putchar(top);top=ot C
14:*++sp=top;top=getchar();C 9:top*=ot;}}fth(){_W(3);_W(4);_W(1);
w=*op;nt=5;nt=2;ip=*op;nt=w;nt=ip-1;for(w=6;w<16;)_W(1),nt=w++;op
[1]=*op;*op+=512;for(;;)exec(op[ip++]);}

Hint

The encrypted hint attached to the interpreter, in xxd hex dump format:

00000000: 726a 0346 0130 3030 3107 3130 30e6 3130  rj.F.0001.100.10
00000010: 3081 ce1b 9e20 3030 3034 c531 3030 c5c5  0.... 0004.100..
00000020: 2922 d6cf cfcf cfdc bd23 1379 4b58 49d4  )".......#.yKXI.
00000030: 227b 0001 8c66 7253 ef87 2cfd 73ec aa09  "{...frS..,.s...
00000040: cb05 fcff 79f6 289f a3ee 47e2 1b89 b5cb  ....y.(...G.....
00000050: 2ac3 2d80 1661 be59 aea9 44a6 bff5 64c2  *.-..a.Y..D...d.
00000060: 42d9 94b9 3d76 c3a8 75fe 5b43 1142 d9ca  B...=v..u.[C.B..
00000070: 6019 ebbb 2542 3b9d 3112 ea65 9252 4257  `...%B;.1..e.RBW
00000080: 2855 524a 3b13 0323 5921 0d11 830c dd27  (URJ;..#Y!.....'
00000090: b7e1 a282 f8b3 c542 8ef4 d697 dce1 f240  .......B.......@
000000a0: 856a 120e ccf8 4728 eda4 2fce 934d b520  .j....G(../..M.
000000b0: b807 3339 783b e782 7ebf f85d 5d76 0afd  ..39x;..~..]]v..
000000c0: dfaf 0252 0c62 fcf7 1a36 84bd 1362 bad7  ...R.b...6...b..
000000d0: 8a86 2329 4d2b e3e8 a0cc 8e09 341f a3e3  ..#)M+......4...
000000e0: 6d96 3e4a 42dc 345c 4e46 0105 ef24 0421  m.>JB.4\NF...$.!
000000f0: ef72 142a e3d2 5f8f 106a 9305 92f8 6f8f  .r.*.._..j....o.
00000100: effc 9dc2 ed9e a8d7 196d d740 ddeb 9d3c  .........m.@...<
00000110: 40c8 1e05 b363 f470 8c0f 8345 cb1e 22af  @....c.p...E..".
00000120: bfbd 3b34 f442 2b52 69cd c4a8 dbff 54e5  ..;4.B+Ri.....T.
00000130: 0b08 9fd2 725b 28c4 ae48 c451 be5a a44f  ....r[(..H.Q.Z.O
00000140: c6bd 58b2 c860 5761                      ..X..`Wa