bftree
Brainfuck without a tape. The cells hang on a tree, and the program draws the tree first.
None1, 2025 · Turing complete: with unbounded memory · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
None1 made bftree in 2025. A program starts with its own memory, written as a tree. The first line gives the number of nodes, and each line after it joins two nodes with an edge. Then comes brainfuck, but < and > are gone. To move, *k* steps to the k-th smallest neighbour of the current node, counting round when k is larger than the number of neighbours.
Read the story
A chain of nodes 1 2, 2 3, 3 4 is a tape again. From node 2, *1* goes back to node 1 and *2* goes on to node 3. The specification soon adds bfgraph, where the first line also gives the number of edges and the memory can be any graph, with cycles.
The machine
| Command | Does |
|---|---|
+ - | Add or take 1 from the current node, a byte that wraps |
. , | Print the node as a byte; read a byte into it |
[ ] | Loop while the node is not 0 |
*k* | Move to the k-th smallest neighbour, counting round |
The pointer starts on node 1. One number on the first line means a tree of n nodes and n - 1 edges; two numbers mean a graph of n nodes and m edges. Every other character is a comment.
Example
The HI! program uses a chain of four nodes.
The HI! program uses a chain of four nodes. Node 1 counts eight times nine into node 2, which makes 72, an H. Node 3 counts eight times four into node 4, a space that becomes !.
The same program as bfgraph, with the number of edges on the first line.
A cat never moves, so a tree of one node and no edges is enough.
The specification's Python interpreter sorts the neighbours of only one node, by a slip in its loop. The text asks for the smallest neighbour, so this implementation sorts every node's neighbours. The two agree in the specification's examples. That interpreter also reads the program from standard input, so its , always reads 0.
Patterns it teaches
- Turing tarpit: brainfuck with a tree for a tape. With values that do not wrap, a chain of three nodes is enough for three-cell brainfuck.
- Encoding tricks: the shape of the memory is part of the program.
Further
See also
bftree builds on Brainfuck.
Tree-based
Brainfuck derivatives
Write your own in Run Convert a program from bftree
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: bftree.
Command line
shib run bftree -e '4
1 2
2 3
3 4
++++++++[*2*+++++++++*1*-]*2*.+.*2*++++++++[*2*++++*1*-]*2*+.'shib manual bftreeSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/bftree.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org