Brainfuck programming language

HomePage | Recent changes | View source | Discuss this page | Page history | Log in |

Printable version | Disclaimers | Privacy policy

A minimalist computer programming language created by Urban Mueller. Also known as Brainf*ck, Brainf***, or just BF.

Mueller's goal was to create a simple Turing complete programming language which could be implemented with the smallest possible compiler. The language consists of eight statements. The original compiler, written for the Amiga, was 240 bytes in size.

As the name suggests, Brainfuck programs tend to be difficult to comprehend, perhaps so much so as to drive the programmer insane. However, the Turing machine, and therefore Brainfuck, can accomplish any computing task. Disregarding the apparent difficulty in programming certain tasks in brainfuck, it is certainly possible to do so.

The language is based on a simple machine model consisting of an array of bytes initialized to zero, a pointer into the array (initialized to point to the first byte of the array), and two streams of bytes for input and output.

The eight language statements, each consisting of a single letter, are the following:

CharMeaning
> increment the pointer.
< decrement the pointer.
+ increment the byte at the pointer.
- decrement the byte at the pointer.
. output the byte at the pointer.
, take byte input and store it in the byte at the pointer.
[ jump forward to the statement after the corresponding ] if the byte at the pointer is zero.
] jump back to the corresponding [.

Brainfuck programs can be transliterated into C using the following substitutions:
Assuming ptr is of type char*

> -> ++ptr; < -> --ptr; + -> ++*ptr; - -> --*ptr; . -> putchar(*ptr); , -> *ptr = getchar(); [ -> while (*ptr) { ] -> } An example is the following Hello world program: >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.- - - - - - - -.+++.- - - - - - . - - - - - - - -.[-]>++++++++[<++++>- ]<+.[-]++++++++++. Brainfuck is interesting as in this case, a "Hello World" program is neither small nor easy to implement! See /Examples for more examples of Brainfuck programs.


Sources and further reading:

Brian Raiter, Muppetlabs. Brainfuck: An Eight-Instruction Turing-Complete Programming Language (http://www.muppetlabs.com/~breadbox/bf/)
Panu Kalliokoski. The Brainfuck Archive (http://esoteric.sange.fi/brainfuck/)
Cat's Eye Technologies. Brainf*ck (http://www.catseye.mb.ca/esoteric/bf/)

/Talk