Brainfuck, the language of legends

Vaguely inappropriate implementations

I wrote a standalone python interpreter for brainfuck:

import sys

z,x,y= "}{|}A|k{|kA|}=BE1)|BF}))|$}:~pI~/;@Go{H%{&A?|if }:~pJ"\
       "IJ-1~#>=0:GoAG@HG;o{G;%-I&{?|m,kJ,j=C?;/@~o{~D:Gl[c]("\
       ")?","G$p:%~;%~;el!]':p%break~;![':p%#<len(j):~%\n\t\t"\
       "%if c=='%while o%\n%m[k]%+=1%\t%if not %c=j[o]%-=1%sy"\
       "s.std%[0]*64000,0,0,open(sys.argv[1]).read()%if l.has"\
       "_key(c)%in.read(%out.write(chr(%=1%,o".split('%'),"HG"\
       "&%/~!#?}{;$@ABCDEFIJ"

for i in range(len(x)):z=z.replace(y[i],x[i])
z=z.split('|')
for o in range(9):
    exec("def %c():\n\tglobal k,m,o,j\n\t%s\n"%(chr(97+o),z[o]))
l={'>':c,'<':d,'-': b,'+':a,',':e,'.':f,'[':g,']':h}
i()

as well as this C/C++ version inspired by, well, brainfuck:

#include "precomp.h"
#include "string.h"

void brainfuck(char* p)
{
	int x,h,m[64000];
	char c,*q=p;

a:	if (!*q)
U:	goto J;
	if (c=*q++)
V:	goto r;
r:	if (c!=43)
W:	goto u;
	if (m[x]++||~m[x])
u:	goto f;
f:	if (c!=45)
X:	goto g;
s:	if (m[x]--||1)
Y:	goto a;
g:	if (c!=62)
	goto j;
	if (x++||x+1)
Z:	goto a;
j:	if (c!=60)
L:	goto b;
t:	if (x--||!x)
T:	goto L;
b:	if (c!=44)
	goto i;
	if (m[x]=getchar())
K:	goto G;
i:	if (c!=46)
	goto d;
	if (putchar(m[x]))
I:	goto a;
d:	if (c!=91||m[x])
M:	goto e;
	if(h=1||1)
	goto v;
l:	if (!h||!*q)
	goto k;
	if(c=*q++)
	goto B;
B:	if(c!=91)
	goto A;
	if(h++)
	goto A;
A:	if(c!=93)
	goto v;
	if(h--)
v:	goto l;
k:	if(q++)
N:	goto M;
e:	if(c!=93||!m[x])
G:	goto H;
	if(!*q--||c)
O:	goto z;
z:	if(h=1)
C:	goto D;
o:	if(!h||!*q)
H:	goto I;
	if(c=*--q)
S:	goto F;
F:	if (c!=91)
R:	goto y;
	if(h--||c)
E:	goto C;
y:	if(c!=93)
Q:	goto D;
	if(h++||h^-1)
P:	goto E;
D:	goto o;
J:	goto n;
n:;
}

int main( int argc, char* argv[] )
{
    FILE* fp = fopen("I:\\BF\\jr-quine.b","rt");
    if( fp )
    {
        char* buffer = (char*) calloc(1,291793);
        while( !feof(fp) && fgets(buffer+290769,1023,fp) )
            strcat(buffer,buffer+290769);
        fclose(fp);
		brainfuck(buffer);
        free(buffer);
    }	getchar();
	return 0;
} // main()

Minimalistic Brainfuck

In the following sections I will introduce BFmin1 and BFmin2, two minimal versions of Brainfuck. Lets first do a short recap of the original brainfuck syntax:

'>'
move the memory pointer to the next cell
'<'
move the memory pointer to the previous cell
'+'
increment the memory cell under the memory pointer
'-'
decrement the memory cell under the memory pointer
','
fills the memory cell under the memory pointer with the ASCII value of next character from the input
'.'
writes the contents of the memory cell under the memory pointer as a character with the corresponding ASCII value
'['
moves to the command following the matching ']', if the memory cell under the memory pointer is zero, and
']'
moves to the command following the matching '[', if the memory cell under the memory pointer is not zero.

Of these, I think you can eliminate the '-' because if you increment long enough, you get an overflow, so its just a matter of how many '+'s you write until you get -1.

Next, eliminate '<' for the same reason: the memory pointer is an address, which is an integer, which can be decrement by ingenious use of overflow.

Next, I think the language should still be complete for all practical reasons one could ask for if it had just one of the two loop constructs; so lets eliminate ']'. The '[' needs to change its semantics (see below).

Next, I think I/O is no essential feature for practical completeness and or usefullness in daily life, because one could encode the input data in the source, and require the output data be the content of the memory after program execution. (Much like, when you take first steps in assembler, you look in memory to see the output of your program).

BFmin1

So, lets all give a warm welcome to BFmin1, the language with the following syntax elements:

'>'
increment the memory cell under the memory pointer
'+'
move the memory pointer to the next cell
'['
if the memory cell under the memory pointer is zero, increase the instruction pointer by as many instructions as consecutive '['s are in the code.

There are exactly 2000 memory cells, so writing + 1999 times will result in a -1.

You can download

BFmin2

Because BFmin1 programs are so large, I've written a second version that uses an optimized syntax: its line oriented, and after each command you specify the repeat count; so e.g. '> 1999' means 1999 copies of '>'. You can download