Professional Documents
Culture Documents
Tutorial BF
Tutorial BF
In this tutorial, I'll try to teach you the brainfuck language with simple words. After that, things will go
more advanced.
If you are a n00b, all you have to do is sit on your chair and start reading. If you are more advanced or
you know brainfuck, check for any mistakes.
brainfuck -note that 'b' is in lowercase-, also known as brainf*ck, brainfsck or bf (in short), is an esoteric
programming language and it's extreeme minimalistic. brainfuck is created by Urban Müller in 1993 with
the intention of designing a language which could be implemented with the smallest possible compiler.
Urban Müller managed to make his compiler for Amiga OS 240 bytes big! Then, some implemetions
(Though he improved upon this later -- he informed me at one point that he had managed to bring it
under 200 bytes).
You don't really need it... It's good to make very small programs, by using a small compiler. Also, when
using interpreter, may your programs be cross-platform
* Well, first of all, I must remind you that brainfuck is designed to be small. That means, no functions, no
calling API etc.
* However, brainfuck doesn't have variables... How do you hold values? That's for later...
Simply: NOTHING! Even just paper and pencil is nice... ok ok ok For passing the program to your
computer you need an interpreter or a compiler (I'd prefer an interpreter) and a text editor. Even
notepad / nano or sth like that is nice!
You also need a keyboard!
OK that was the big theory... now let's move on the practical part!
Well, why is brainfuck so difficult to be used? That's why brainfuck has just 8 commands, and they are all
single ascii characters... well, that's not even assembly!
Also, brainfuck has a pointer, that's called -so simply- 'the pointer', which is free to move arround
within an array of 30000 bytes. The pointer is initialized to point to the beginning of the array and the
30000 bytes are all initialized to 0 (zero).
03 ===========================================================
> Moves the pointer one step to the right of the array. That
04
means that increases the byte pointer.
< Moves the pointer one step to the left of the array. That
05
means that decreases the byte pointer.
06 + Increases by one the pointed byte.
CODE C Language
1 + Adds 1
2 + Adds 1 to 1
3 + Adds 1 to 2
4 + Adds 1 to 3
5 + Adds 1 to 4
6 + Adds 1 to 5
++- Adds 1 the 6 and then subtracts 1 from 8; outputs EOF (NOTE THAT I
7
DIDN'T USE COMMMAS IN 'COMMENTS'
THAT'S BECAUSE IF I USE COMMA; THE COMPILER / INTERPRETER WILL CATCH IT!
8
:P
Could be written as well:
CODE C Language
1 ++++++++-.
Remember: the values which are stored in the array, they are single characters. When output, they're
shown as explained in ASCII table (scroll down to see it when you finish the tutorial)
Now, you've learned much about brainfuck. Much enough to make programs! You don't
need Me to tell You how to do special things, just like division... Find out yourself! (Even if
there's in the links )
YOU CAN ALSO SCROLL DOWN TO SEE THE LINKS AND COMMENT THE TUTORIAL!
________________________________________________________________________________
3.0
Well, you want to make a brainfuck interpreter and don't know how to start? That's very simple. Read
the tutorial!
How did I start? By telling you that there's a byte array with 30000 places and a byte pointer. In C/C++,
you can do
CODE C Language
1 char array[30000];
2 char *ptr;
After that, you need file i/o to read the source files. On the continue, you may want to process every
readed character. It's
simple. Just read the tutorial. The description each command says exactly what you have to do . You
may want to pass all
the commands in an array and then do you job! (that's more easy for '[' and ']' commands if you don't
know good file i/o for
the language in which you are programming the interpreter, but you have limited space of commands).