📜 ⬆️ ⬇️

To start or introductory course in esoteric language

This is of course a hobby, though ...

Brainfuck coined by Urban Muller in 1993, mostly for fun. A unique, quite interesting for yourself Turing-complete programming language with a compiler size of 240 bytes! It uses only 8 commands, each of which is written in one character. The program in the language Brainfuck is a sequence of these very commands.

The machine, which is controlled by the Brainfuck commands, consists of an ordered set of cells and a pointer to the current cell, something like a stack and an offset in it. The possibility of an I / O mechanism is also implemented, then it will be clear by example.

List of all language commands

> move to the next cell
< go to previous cell
+ increment the value in the current cell by 1
- decrement the value in the current cell by 1
. print the value from the current cell
, enter value from outside and save to current cell
[ if the value of the current cell is 0, go forward in the program text to the cell following the corresponding closing one ] (taking into account nesting)
] if the value of the current cell is not 0, go back through the program text to the cell following the corresponding opening [ (with nesting)

Initially the number of cells was 30 thousand, each in byte size. By default, the pointer is in the left cell (cell 0); the values ​​of all cells are equal to 0. The input / output of values ​​occurs according to the ASCII table, more precisely, by the numerical offset in this table. For example, 32 "+" signs and a dot - will display a space in the zero position, the next ">" sign will take us to the next cell. If you now enter 72 "+" signs and a dot, the letter "H" will be displayed. The construction +++[.-] is essentially a loop, we put the value 3 in the cell, display the value from the cell and reduce it, respectively, the output of characters with codes 3, 2 and 1 would turn out. For PHP it would look like this: for ($i = 3; $i > 0; $i--) print chr($i);
')
Language options may differ from versions!

"Hello World!"

+++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++.+++++++++++++++++
++++++++++++.+++++++..+++.-------------------
---------------------------------------------
---------------.+++++++++++++++++++++++++++++
++++++++++++++++++++++++++.++++++++++++++++++
++++++.+++.------.--------.------------------
---------------------------------------------
----.-----------------------.


Actually 72 output “H”, in the same cell we add another 29 output “e”, etc., by manipulating the addition / decrease of the value in one single cell. Values ​​are not written to the cell, but displayed on the fly.

Bleed "Hello World!"

++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++
.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.
------.--------.>+.>.


So say a textbook example. Based on preliminary preparation of 4 cells with values ​​of 70, 100, 30 and 10, to make it easier to add or subtract. The ++++++++++[>+++++++>++++++++++>+++>+<<<<-] block ++++++++++[>+++++++>++++++++++>+++>+<<<<-] will perform the operations 10 times in a loop - add 7 in the first cell, 10 in the second, 3 in the third and 1 in the fourth, and then return to cell 0 and reduce it. In subsequent actions, you can already figure it out and so.

Soft

Ubuntu - bf (a fast Brainfuck interpreter)
Windows - Brainfuck Developer , Brainfuck Compiler

It is useful to read

Lecture Unread by the Author at the Hidden Institute of Non-Existing Standards

That's actually to start, I hope it will come in handy)

Source: https://habr.com/ru/post/45034/


All Articles