Brainfuck Substitutor
Brainfuck where any character can be made to stand for a piece of code, even +.
2017 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Brainfuck Substitutor, BFS for short, is brainfuck with one addition. A character can be given a piece of code, and from then on every time it is read it is replaced by that code. A definition may use earlier ones, so b can be four as and stand for 20 plus signs. A brainfuck command can be given new code too, and then + adds 5.
Read the story
The replacement happens while the program is read, not while it runs. A definition only changes the lines after it.
The machine
There are two ways to write a program.
| Mode | Definitions | Code |
|---|---|---|
| Succinct, the default | All on the first line, each a name followed by its code, a+++++baaaa | Every line after the first |
Verbose, flag -v | A line a=+++++, anywhere | Every other line |
In succinct mode a character that is not a command and not yet defined starts the next name. So the eight commands cannot be names there, while = can. A succinct program needs at least two lines. The rest is brainfuck on byte cells.
The reference interpreter takes -v on its command line. In this implementation an input whose first line is -v turns verbose mode on, and the program reads what follows that line.
Example
A program in succinct mode.
A program in succinct mode. a is 5 plus signs, b is four as, and bb adds 40, the code of (.
The same program in verbose mode, and a program that gives + new code. Eight plus signs of five each make 40 again.
Hello, World! with a for 16 plus signs and b for 16 minus signs. Its code line is 111 characters. Plain brainfuck that counts in one cell from each character to the next needs 366.
Patterns it teaches
- Turing tarpit: brainfuck underneath, with a macro step in front.
See also
Brainfuck Substitutor builds on Brainfuck.
Brainfuck derivatives
Write your own in Run Convert a program from Brainfuck Substitutor
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: brainfuck-substitutor.
Command line
shib run brainfuck-substitutor -e 'a+++++baaaa
bb.'shib manual brainfuck-substitutorSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/brainfuck-substitutor.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org