BrainJuice
Brainfuck with the juice added back. Arithmetic, strings, numbers, and cells that run as code.
A Monitor · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
A Monitor made BrainJuice from brainfuck. All eight of brainfuck's commands are there, on a tape that runs both ways and holds signed integers. Around them come 20 more. Some save typing, such as a string that prints itself or :65: for a number. Others do arithmetic between a cell and the next one.
Read the story
The last few treat the tape as code. # runs the one character whose code is in the cell, and \ runs the characters in the cells that follow, up to the first one that is 0 or less. A backtick blocks a character so that it no longer runs at all.
The machine
| Command | Does |
|---|---|
+ - < > [ ] , . | As in brainfuck |
0 | Set the cell to 0 |
;c | Set the cell to the code of c |
:65: | Set the cell to the number |
"text" | Print the text |
* / ^ % | Combine the cell with the next one |
~ | Natural logarithm, without the fraction |
$ @ | Pointer to cell 0; pointer to the cell's value |
& | Set the cell to the pointer |
{ } | Swap with the cell before or after |
( ... ) | Run once if the cell is above 0 |
_ | | Look up the cell its value points to, once or twice |
# \ | Run the cell as a character; run the next cells as a program |
| Backtick | Block or unblock the character with the cell's code |
At the end of the input , reads 0. The cat and the interpreter both stop that way.
Example
The truth machine sets the next cell to the code of 0 and subtracts it from the input.
The truth machine sets the next cell to the code of 0 and subtracts it from the input. If 1 is left, it prints 1 forever. If 0 is left, it skips the loop and prints 0 once.
The BrainJuice interpreter in BrainJuice is eight characters. It reads the input into cells 1 and up, goes back to cell 0 and runs what follows it.
Patterns it teaches
- Turing tarpit: brainfuck underneath, with the tarpit widened.
- Code as data: characters on the tape run as commands.
- Metacircular interpreter: the interpreter is one command and a read loop.
Further
See also
BrainJuice builds on Brainfuck.
Brainfuck derivatives
Cell-based
Write your own in Run Convert a program from BrainJuice
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: brainjuice.
Command line
shib run brainjuice -e ',[.,]' --input 'cat'shib manual brainjuiceSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/brainjuice.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org