Loose Circular Brainfuck
Brainfuck on a ring of 30 cells, with loops that forgive a missing bracket.
Maurice Ling, 2012 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Maurice Ling made Loose Circular Brainfuck, or LCBF, as a generic way to try out languages of op codes. It keeps the eight commands of brainfuck and changes two things. The tape is a ring, so moving past one end comes back at the other. And a bracket without its partner is no error. A ] with no [ has nowhere to jump back to, so the run goes on, and a [ with no ] ends the run when its cell is 0 or below.
Read the story
The specification gives the language as a Python interpreter of about 100 lines, and this implementation runs as that interpreter does, quirks included.
The machine
| Char | Does |
|---|---|
+ - | Add or subtract 1; cells hold integers without bound |
> < | Move round the ring of 30 cells |
. | Output the cell as a decimal number |
, | Take the next input byte, or 0 when there is none |
[ | Go on if the cell is above 0, else jump past the matching ] |
] | Jump back past the matching [ if the cell is above 0 |
Three quirks come from the interpreter. Leaving a loop at ] skips the command right after it, because the interpreter steps past the ] twice. A cell below 0 counts as false. And the ring has a hole, as the wrap only happens past position 30, so cell 29 leads to a position 30 with no cell behind it.
Example
The specification's interpreter ends by running five programs.
The specification's interpreter ends by running five programs. The first counts down.
The third has a ] with no [. The cell under it is 1, the interpreter finds no match and goes on.
The fifth nests two loops. Each time round the outer loop, the inner loop adds 3 to a cell and prints it four times, so the numbers climb from 3 to 60. The . after the inner ] would print a 0, but leaving the loop skips it every time.
Patterns it teaches
- Turing tarpit: 30 cells of unbounded integers are enough for a counter machine.
See also
Loose Circular Brainfuck builds on Brainfuck.
Brainfuck derivatives
Cell-based
Write your own in Run Convert a program from Loose Circular Brainfuck
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: loose-circular-brainfuck-lcbf.
Command line
shib run loose-circular-brainfuck-lcbf -e '++>+++++<.-]>>>+++.'shib manual loose-circular-brainfuck-lcbfSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/loose-circular-brainfuck-lcbf.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org