esolang

Cerberus

Three lines of dots and dashes. The size of each patch is the instruction.

2020 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: 0

The idea

Every Cerberus program has three lines, like the dog has three heads. The lines hold only . and -, and the first column with anything else ends the program. Cells of one character that touch up, down, left or right form a group, and the size of the group picks the command. Two dots read a number and two dashes print one.

Read the story

The pointer walks the middle line from left to right. It runs a group's command once, when it steps into the group. The top and bottom lines only shape the groups.

The machine

Size.-
1Push 1Push -1
2Read an integerPop and print it
3Pop A, then B, push A-BPop A, push A! or, when A is not above 0, -((-A)!)
4SwapDuplicate
5NothingNothing
6Pop A, mark this place as APop A, jump to mark A

A command with too few items on the stack does nothing. A jump to a mark that was never set goes on to the right. After a jump the pointer stands on the marked cell and does not run it again.

Example

The truth machine.

The truth machine. Along the middle line its groups read a number, duplicate it, push 1, set mark 1, duplicate, print, duplicate and jump to the mark the number names. Only 1 has a mark, so 1 prints forever and any other number prints once.

The cat is 79 columns wide and runs push 1, mark 1, read, duplicate, print, push 1 and jump 1 forever. This implementation stops when the input runs out.

Expected: 42

Patterns it teaches

Further

Pattern-based

Stack-based

Write your own in Run Convert a program from Cerberus

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run cerberus -e '.-...-..--.--....-..-.-..--
.-.---..-.--.----..-..-..--
--.-..-.--.-.....-.-..--.--' --input '0'
shib manual cerberus

Source

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

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

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