I was feeling a bit bored, so I wrote turing complete a brainf*ck interpreter, and an optimising brainf*ck-to-java compiler.
Unfortunately, the compiler doesn’t produce a turing complete program, as it limits the cell buffer to 30000 entries.
The compiler turns the following brainf*ck:
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
into this java code:
/**
* Compiled by BrainFuckCompiler by Mojang Specifications
*/
public class Foo
{
public static void main(String[] args) throws java.io.IOException
{
StringBuffer sb = new StringBuffer();
int p = 0;
byte[] b = new byte[30000];
b[p]+=10;
while(b[p]!=0)
{
b[++p]+=7;
b[++p]+=10;
b[++p]+=3;
++b[++p];
--b[p-=4];
}
sb.append((char)(b[++p]+=2)).append((char)(++b[++p])).append((char)(b[p]+=7)).append((char)(b[p])).append((char)(b[p]+=3));
sb.append((char)(b[++p]+=2)).append((char)(b[p-=2]+=15)).append((char)(b[++p])).append((char)(b[p]+=3)).append((char)(b[p]-=6));
sb.append((char)(b[p]-=8)).append((char)(++b[++p])).append((char)(b[++p]));
System.out.print(sb.toString());
}
}
When that java program is run, or when the corresponding brainf*ck code is run through the interpreter, it spits out the following on standard out:
[quote]Hello World!
[/quote]
The compiled version runs about four-five times as fast with the output heavy “hello world” test program.
If the forums didn’t censor the word “brainfuck” even in urls, you’d be able to click these two links to get the source code:
brainfuck compiler source code
brainfuck interpreter source code
… but now you’ll have to manually enter the urls into your browser if you want the source code. :-\