Leafuck
Brainfuck on a binary tree. The only question a loop can ask is whether this node has a child.
Rainwave, 2026 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
Rainwave made Leafuck in 2026, first under the name Navitree. It keeps brainfuck's pointer and loop but drops the tape and the numbers. The data is a binary tree that starts as a single root node and only grows. Moving to a child that is not there makes it, and nothing is ever deleted.
Read the story
A node holds nothing but its links. So [ cannot test for zero. It tests for a leaf, a node without children, and that leaf check is where the name comes from. The specification says Leafuck is Turing complete, as Bitwise Cyclic Tag compiles into it.
The machine
| Command | Does |
|---|---|
< > | Move to the left or right child, making it if needed |
^ | Move to the parent; at the root it is an error |
.x | Print the character x |
[ | Jump past the matching ] if the node is a leaf |
] | Jump back to the matching [ |
Every other character does nothing. The program has no input.
Example
The 3x5 rectangle hangs a left chain of three nodes under the root and loops while the node is not a leaf.
The 3x5 rectangle hangs a left chain of three nodes under the root and loops while the node is not a leaf. Each turn hangs a chain of five right children and prints a star at every node that has a child. But after the stars it climbs back only three of the five nodes, so the < lands on a new leaf and the loop ends after one row. The specification shows three rows; its own interpreter, which this implementation follows, prints one.
With five carets it climbs back to the chain and prints the three rows.
Patterns it teaches
- Turing tarpit: five commands and a print, with a tree in place of the tape.
Further
See also
Tree-based
Write your own in Run Convert a program from Leafuck
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: leafuck.
Command line
shib run leafuck -e '.H.e.l.l.o. .w.o.r.l.d.!'shib manual leafuckSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/leafuck.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org