Friday, 18th September, 2009
Baby’s First Compiler
So I was bored for a minute, and whilst slightly drunk, a thought hit me.
I should write a brainfuck compiler! But wait, there’s brainfuck to C already. The only examples I’d seen were brainfuck C equivalents.
> : Increase pointer by one
< : Decrease pointer by one
+ : Increase value at pointer by one
- : Decrease value at pointer by one
. : Output character at pointer
, : Read character at pointer
For fun, I also put in a debug, same as the original implementation:
# : Print debug info (Value of first 10 cells and the current pointer value)
The only real issue that I’ve found is that after every character output, Python prints a space :-(. This compiles brainfuck to Python code :-).
Ahh well
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Done! :-D
P.S.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++.-.---------.[-]+++++++++++++++++++++++++++++++++.-.++++++++++++++++++++++++++.-------------.[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.