For starters or an introductory course in esoteric language

    This is of course a hobby, though ...

    Brainfuck was coined by Urban Muller in 1993, mainly for fun. A unique, quite interesting Turing-complete programming language with a compiler size of 240 bytes! It uses only 8 commands, each of them is recorded with one character. A Brainfuck program is a sequence of these same commands.

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

    List of all language commands

    >   go to the next cell
    <   go to the 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 the value from the outside and save it in the current cell
    [   if the value of the current cell is 0, go forward in the program text to the cell following the corresponding closing ] (taking into account nesting)
    ]   if the value of the current cell is not equal to 0, go back in the program text to the cell following the corresponding opening [ (taking into account nesting)

    Initially, the number of cells was thought to be 30 thousand, each in byte size. By default, the pointer is in the left cell (cell 0); the values ​​of all cells are 0. The input / output of the values ​​occurs according to the ASCII table, more precisely, according to the numerical offset in this table. For example, 32 "+" signs and a dot - will display a space at the zero position, the subsequent ">" sign will transfer us to the next cell. If you now enter 72 "+" signs and a period, the letter "H" is displayed. The design +++[.-]is essentially a cycle, we bring the value 3 into the cell, display the value from the cell and reduce it, respectively, we get the output of characters with codes 3, 2 and 1. In PHP, it would look like this: for ($i = 3; $i > 0; $i--) print chr($i);

    Language parameters can differ from varieties!

    "Hello World!"

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


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

    Uploaded "Hello World!"

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


    So to say a textbook example. Based on preliminary preparation of 4 cells with values ​​of 70, 100, 30 and 10, so that it is easier to add or decrease. Block ++++++++++[>+++++++>++++++++++>+++>+<<<<-]10 times will perform operations in the cycle - add 7 in the first cell, 10 in the second, 3 in the third and 1 in the fourth, then return to cell 0 and reduce it. In the next steps, you can already figure it out like that.

    Soft

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

    Useful to read

    Lecture, unread by the author at the Secret Institute of Non-existent Standards.

    Actually, for starters, I hope it will come in handy)

    Also popular now: