esolang

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

Expected: Hello, World!

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

CommandDoes
> < + - . , [ ]Brainfuck on the child tape under its IP1
{ } % &Move IP1 or IP2 on this tape
*Set IP1 to IP
vSkip the next byte
;Jump past the next ;
' @ sPrint the byte under IP1, under IP2, or var
# øLoad the byte under IP1 into var or into the child's var
A BLower or raise var
0 to 9Count down by one, 0 back to 9
qIf var is a letter, go back to the nearest digit
rAdd var to the end of the child tape
V W X Y ZTests that skip the next command when true
t uRun 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.

Expected: Hello, World!

Plain Brainfuck runs on the child tape. The specification's version leaves out the comma.

Expected: Hello World!

The byte to decimal converter writes three 0 bytes to the child tape and counts the input down into them.

Expected: 065

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, x and six neighbour commands rewrite the program as it runs.
  • Code as data: the text a program prints is read from its own tape.

Further

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 brb

Source

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