BRB
Brainfuck with 102 commands, where every tape is code, data and the parent of another tape.
Peter Larsen, 2011 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 8 known programs · Test method
Run it
The idea
Peter Larsen made BRB in 2011. The name stands for Be Right BRB. It starts from the eight commands of Brainfuck and adds 94 more. The program is itself a tape, and every tape has a child tape, a byte variable var that starts at 65 and three pointers, IP for the code and IP1 and IP2 for data.
Read the story
Code and memory are the same cells. The digits count down each time they run, x turns itself into v, and six commands write into the bytes on either side of the one running. The Brainfuck commands work on the child tape, and t runs that child tape as a program of its own.
The machine
| Command | Does |
|---|---|
> < + - . , [ ] | Brainfuck on the child tape under its IP1 |
{ } % & | Move IP1 or IP2 on this tape |
* | Set IP1 to IP |
v | Skip the next byte |
; | Jump past the next ; |
' @ s | Print the byte under IP1, under IP2, or var |
# ø | Load the byte under IP1 into var or into the child's var |
A B | Lower or raise var |
0 to 9 | Count down by one, 0 back to 9 |
q | If var is a letter, go back to the nearest digit |
r | Add var to the end of the child tape |
V W X Y Z | Tests that skip the next command when true |
t u | Run the child tape |
_ | End this tape |
Pointers on the program's own tape wrap around its ends. The child tape grows with zeros as far as a command reaches. R opens files, and with a file name it stops, since there are no files.
Example
The specification gives four Hello World programs.
The specification gives four Hello World programs. The second jumps over its text and then prints it one byte at a time with IP1.
This one loops with q. It loads the R it skipped into var, and each pass lowers var by one and goes back to the digit while var is still a letter. That makes 18 passes, which carry IP1 to the H. A second loop counts down from the skipped M and prints 13 bytes.
Plain Brainfuck runs on the child tape. The specification's version leaves out the comma.
The byte to decimal converter writes three 0 bytes to the child tape and counts the input down into them.
The false quine sets IP2 to its last byte with &, then prints from IP1 until the two meet.
Patterns it teaches
- Self-modifying code: digits,
xand six neighbour commands rewrite the program as it runs. - Code as data: the text a program prints is read from its own tape.
Further
See also
Self-modifying
Write your own in Run Convert a program from BRB
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: brb.
Command line
shib run brb -e ',[.,]' --input 'cat'shib manual brbSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/brb.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org