esolang

BTree

The program is a binary tree. After each node a ternary digit says left, right or back up.

TuxCrafting, 2019 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: -

The idea

TuxCrafting made BTree in 2019. A program is a list of nodes that fill a binary tree level by level, so the source can be drawn as a tree with the root on top. After a node has run, the accumulator decides where to go next. At -1 the walk goes to the left child, at 1 to the right child and at 0 back up to the parent. Walking off the tree ends the run.

Read the story

All data is balanced ternary digits, -1, 0 and 1, in two accumulators and a deque. The specification proves BTree Turing complete by compiling cyclic tag systems into it.

The machine

A node is one character, or several written as ;x;y;z with the last one bare. Whitespace and { comments } do not count.

InstructionDoes
- 0 +Set A to -1, 0 or 1
^Swap A and B
a bPut A at the end or at the start of the deque
A BTake the start or the end of the deque into B
& |The minimum or the maximum of A and B, into A
=A becomes 1 if A equals B, else -1
!Negate A
i oRead or print a digit as - 0 +

Every other character does nothing, which is how . fills a place in the tree.

Example

The truth machine has six nodes.

The truth machine has six nodes. The root reads a digit and copies it into B through the deque. On - it goes left, prints - and walks off the tree below a leaf.

On + it goes right, prints + and sets A to -1, which leads to the child 0. That sets A to 0 and sends the walk back up, so it goes between those two nodes and prints + for ever.

A program of one node, which reads three digits into the deque and prints them from the end.

Expected: -0+

Patterns it teaches

  • Tag systems: the specification compiles cyclic tag systems into trees of BTree nodes.

Further

Deque-based

Write your own in Run Convert a program from BTree

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: btree.

Command line

shib run btree -e '{ BTree truth machine }
{ "-" is 0 and "+" is 1 }

  ;i;aA
 o     ;^;o;^-
. .   0' --input '-'
shib manual btree

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/btree.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org