esolang

braintuck

Brainfuck read two characters at a time. The second one says how much.

Xradiation, 2021 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: Hello, World!

The idea

Xradiation made braintuck in 2021 to learn, after brainfuck. It keeps brainfuck's eight characters, but the interpreter reads every character together with the one after it. So ABCD is three steps, AB, BC and CD, and every character but the first and the last takes part in two of them.

Read the story

The first character of a pair says what to do and the second says by how much. ++ adds 1, but +- adds the cell to itself, -+ takes the cell from itself and +. adds 0. Most of the work in a program goes into making each pair mean what you want.

The machine

ADoes
+ -Add B to the cell or take it away, modulo 255
> <Move the pointer B cells right or left
.Print the character with code B
,Read a character into the cell, 0 at the end
[ ]Jump past the matching ] if the cell is 0, or back past the [ if it is not
BStands for
+ -The current cell
> <The pointer
,The next input character, which stays unread
[ ] .0
the same as A1, and for .. the cell

Cells count modulo 255, not 256, as in the Python interpreter in the specification. Moving left wraps round the tape so far. Every character outside the eight is dropped before the run, and the last character is only ever the B of a pair.

Example

The Hello World program.

The Hello World program. The specification writes the letters each line makes beside it. One of those is a comma, which is a command, so this implementation leaves that column out.

The first line makes the H by doubling. 3 doubles to 6, 8 to 16, 17 to 34 and 36 to 72. Each +- doubles, and >>[]<< gives the - after it a > to pair with, which takes away the pointer, 0. The last + of a run pairs with . and adds 0, so the 30 plus signs of the second line add 29 and make the e,

  1. Each . pairs with the first character of the next line and prints the cell.

A cat. .+ prints the cell. +, adds the next input character to it, but the , after that reads the character over it.

Expected: Hello

The specification also has a truth machine, ,[.+]... It reads a character, not a digit, so the input 0 prints 0 forever. Only no input, or a 0 byte, makes it print once, a 0 byte, and stop.

The specification's interpreter reads one line of input. It prints each character next to its code, a leftover from debugging, and its commented lines print only the character, as this implementation does.

Patterns it teaches

  • Turing tarpit: brainfuck where every command also sets the size of the one before it.

Further

braintuck builds on Brainfuck.

Brainfuck derivatives

Cell-based

Write your own in Run Convert a program from braintuck

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run braintuck -e ',[.+,]+' --input 'Hello'
shib manual braintuck

Source

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

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

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