Introduction to Brainfuck
Introduction to Brainfuck
Brainfuck - the name - the language! Brainfuck is an esoteric programming language and in it's concept very minimalistic. It was designed by Urban Müller in 1993. He wanted to create a language with the smallest possible compiler - and in fact there are compilers out there with less than 200bytes.The language itself is based on the concept of the turing machine, therefore all the 8 commands of the language are used to iterate over an array which is compararable to the infinite Tape used by the turing machine.
The commands
- >
- Increments the pointer
- <
- Decrements the pointer
- +
- Increments the value of the current cell
- -
- Decrements the value of the current cell
- .
- Prints out the value of the current cell
- ,
- Read a value from the keyboard
- [
- Starts a loop which runs until the current cell value is zero
- ]
- Points back the the beginning of the loop
These 8 commands are all we need :)
Hello World
++++++++++
[
>+++++++>++++++++++>+++>+<<<<-
]
>++.
>+.
+++++++.
.
+++.
>++.
<<+++++++++++++++.
>.
+++.
------.
--------.
>+.
>.
The above code will print out the famous words "Hello World!". You can save the code to a file and run it with an interpreter like "beef", which is available on most linux distributions. Good thing about Brainfuck is, that it ignores all characters but <>,.+-][ so we do can write comments right into the source.
You can check the above source in the Java Applet I've developed for this tutorial. The Applet is able to run a brainfuck program step-by-step, so you can see what happens.
Explanation: The first line will increase the first cell to the value of "10". This value is used as iteration "variable" for the loop. As long as the cell is unequal to "0" the loop will continue. The loop itself modifies some cells next to our first cell and then decreases the first cell by 1, so that after 10 cycles the loop determinates.
Default structures
While-loop
We already used a while-loop to increase cell values. To be continued..Recommended books on this topic
![]() |
The Man Who Knew Too Much: Alan Turing and the Invention of the Computer (Great Discoveries) by David Leavitt |
Comments (0) |
