Another Finite State Brainfuck
Brainfuck with a single cell, where every run of + counts again from 0.
oshaboy, 2021 · Turing complete: no · ●○○ easy · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
oshaboy made Another Finite State Brainfuck in 2021, a brainfuck subset meant to be equivalent to a finite state automaton. The specification says the older Finite State Brainfuck could only check whether an input is 1 or 0. Taking away < and > leaves one cell, but a cell that can still do arithmetic is more like a push-down automaton with room for 256 unary values.
Read the story
So counting is cut short as well. The first + of every run of + sets the accumulator to 0 before it adds 1, and - stops at 0. No count goes higher than the longest run of + in the program, and a program keeps track of things by where it is in the code. The specification makes the accumulator a long long, which, as it says, does not help much.
The machine
| Char | Does |
|---|---|
+ | Add 1; the first + of a run sets 0 first |
- | Take 1 away, unless the accumulator is 0 |
. | Print the accumulator modulo 256 |
, | Read a byte |
[ ] | Loop while the accumulator is not 0 |
Every other character is a comment. , gives 0 at the end of the input, and a run of + means + characters right next to each other.
Example
The truth machine.
The truth machine. It reads a byte and takes 48 away, which leaves 0 for the digit 0 and 1 for the digit 1. On 0 it skips the loop and counts 48 + up to the character 0. On 1 the loop counts its 49 + from 0 each time round and prints 1 for ever.
On a space, which is 32, the - stop at 0 instead of wrapping round as in brainfuck, so the same program prints 0 again.
A - still works on what was read, so ,-. turns b into a. A + would start again from 0.
See also
Another Finite State Brainfuck builds on Brainfuck.
Accumulator-based
Brainfuck derivatives
Write your own in Run Convert a program from Another Finite State Brainfuck
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: another-finite-state-brainfuck.
Command line
shib run another-finite-state-brainfuck -e ',------------------------------------------------[+++++++++++++++++++++++++++++++++++++++++++++++++.]++++++++++++++++++++++++++++++++++++++++++++++++.' --input '0'shib manual another-finite-state-brainfuckSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/another-finite-state-brainfuck.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org