Brain
Brainfuck with the control flow of C added, compiled through LLVM.
Turing complete: yes · ●○○ easy · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Brain sets out to make brainfuck faster and less cramped while running every brainfuck program unchanged. Its compiler goes through LLVM and folds runs of commands into fewer machine instructions. The language adds multiplication and division, a loop that runs a set number of times, a break, and if with else, all things brainfuck has to build by hand.
Read the story
The specification also lists @, a function call, and ^, a jump to a cell, as not implemented. They are ignored like any other character.
The machine
| Command | Does |
|---|---|
+ - < > . , [ ] | As in brainfuck |
* / % | Multiply, divide or take the remainder of the cell by the cell before it |
{ ... } | Run the inside as many times as the cell holds, without counting it down |
! | Leave the innermost loop at once |
? ... ; | Run the inside only if the cell is not 0 |
? ... : ... ; | The same, with the part after : run when it is 0 |
$ | Print the cell divided by 100 |
# | Print debug information |
The 256 in one cell in the specification means cells are wider than a byte. In this implementation they are 32-bit numbers, . prints the low byte, $ prints two decimals and # prints nothing.
Example
The floating number example.
The floating number example. Two cells hold 2 and 1, and eight * double the second to 256.
The if-else example adds 3 when the cell is not 0 and takes 3 when it is.
The break example leaves the loop after one pass, at 6. A counted loop prints the A in the cell before it four times and leaves its own 4 as it was.
Patterns it teaches
- Turing tarpit: brainfuck underneath, with the usual idioms made into commands.
Further
See also
Brain builds on Brainfuck.
Brainfuck derivatives
Write your own in Run Convert a program from Brain
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: brain.
Command line
shib run brain -e '? +++ ;'shib manual brainSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/brain.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org