Brain--

From Esolang
Jump to navigation Jump to search

Brain-- is created by User:H3h3h0h0, and is a superset of brainfuck.

Method of operation

Instead of the linear series of memory cells offered in regular BF, this language is built around a tree-based data structure. Each cell, while still acting the same way when accessed from outside, can itself become an array of cells. The following diagrams show the structuring in comparison to brainfuck:

brainfuck

... [ ] [ ] [ ] [ ] ...

brain--

[ ] [ ] [ ] [ ] [ ] ...
    |-> [ ] [ ] ...
        |-> [ ] ...

The user is provided with a set amount of cells (3000 by default instead of 30000, due to the ability to create new cells as branches) at the start of execution, and they may choose to move the pointer freely between cells, as well as allocating and deallocating additional layers of cells (with the caveat that you cannot move into a 'leaf' cell or deallocate cells that do not exist). When none of the extra operators are used, it results in exactly the same operation as standard brainfuck. However, if they are used, it can result in analogues of data structures typically found in more complex languages, such as linked lists and binary trees. While this may seem like it improves usability at first, the limited additional syntax combined with more complex addressing arguably make this language more difficult to use to its full extent.

Syntax

Besides the traditional <>+-[],. there are 4 other symbols:

@: allocate an additional byte to the end of the current cell, in other words, create an additional branch on the currently pointed cell
#: deallocate the last byte from the current cell (if available), in other words, remove the last branch on the currently pointed cell
?: "inwards" operator, placing the pointer on the first element inside the current cell (if available), in other words, move into and access the subtree rooted at the pointed cell
!: "outwards" operator, placing the pointer on the encapsulating cell (if available), in other words, move to the parent of the current cell

Computational class

Due to the ability to allocate more memory by design (meaning it can act like an unbounded implementation of brainfuck), this language classifies as a Universal Turing Machine.

External resources

Repo with interpreter (by User:H3h3h0h0): Github