Tired of programming languages whose goal it is to make your life easier? Feel like stretching the 'ol grey matter a bit? Why not try coding in Brainfuck!
"Did you say Brainfuck?"
Yup, that's what I said, Brainfuck.
Created by Urban Mueller, Brainfuck is an eight instruction Turing-complete programming language. This means that it can be shown to be equivalent to a Turing machine and therefore capable of performing any computation. (Click here for a Google search on Turing machine.)
"Why would someone create a language with only eight instructions?"
Urban's goal, it seems, was to create a very small compiler and to do that it helps to have a very small language. Urban succeded on both counts, writing a compiler for the Amiga OS ver 2.0 which was only 240 bytes long.
"OK, so tell me about this language."
Brainfuck has no variables, no functions, no conditionals, ... none of the usual constructs we all take for granted in programming languages.
"Now that I know what it doesn't provide, how's about cluing me in on what it does provide?"
OK, here's what you've got:
The instructions all are single characters and are as follows:
Instruction | C equivalent | Description |
> |
p++; |
Increment the pointer |
< |
p--; |
Decrement the pointer |
+ |
a[p]++; |
Increment the byte at the pointer |
- |
a[p]--; |
Decrement the byte at the pointer |
. |
putchar(a[p]); |
Output the byte at the pointer |
, |
a[p]=getchar(); |
Input a byte and store it in the byte at the pointer |
[ |
while(a[p]) { |
Start loop: Execute delimited code until the byte at the pointer equals zero |
] |
} |
End loop: Jump back to the matching [ |
# |
NA |
Dump the values of a[0] thru a[9] to the console. This is not a part of the language, but a debugging command available in most implementations. |
p
represents the pointer: p = 0
to start.
a[p]
represents the byte at the pointer: a[] = 0
to start.
[ some code ]
"And with this I'm supposed to write meaningful code?"
Brainfuck provides everything you need to program (like I said above, it is Turing-complete). As for the meaningful part ... well, that all up to you now, isn't it?
"So... Um... Do 'ya think you can get me started?"
OK. Click here to see our first program.
Home | Introduction | First Program | Input Processing | Building Blocks | Resources | bf2pl