Cerberus

From Esolang
Jump to navigation Jump to search

Every Cerberus program is 3 lines long. It uses a stack and executes commands based on the size of groups of . and -. The first column that doesn't contain only . and - is the end of the program, so anything after that is a comment. The IP starts at the left side of the second line and moves right until the end of the program. If there aren't enough items for a command, it is treated as a no-op.

Commands

Size of Group Character Meaning
1 . Push 1 to the stack.
1 - Push -1 to the stack.
2 . Prompt an integer input from the user and push it to the stack.
2 - Pop and print the top of the stack.
3 . Pop the two top stack elements A and B, and push the difference A-B to the stack.
3 - Pop the top stack element A and compute the factorial A!. If A is positive, simply push A!, else push -((-A)!).
4 . Swap the two top stack elements.
4 - Duplicate the top stack element.
5 . No-op.
5 - No-op.
6 . Pop the top stack element A and associate it as the A-marker identifier with the current instruction pointer location.
6 - Pop the top stack element A. If a marker with this identifier exists, jump to the associated instruction pointer location; otherwise this is regarded as a no-op.

Example Programs

Truth-machine

.-...-..--.--....-..-.-..--
.-.---..-.--.----..-..-..--
--.-..-.--.-.....-.-..--.--

Cat program

An infinitely repeating cat program is implemented in the following:

..-.--...-.---.--.--..-..--.-.---..-..--.--.--.-...-..-.--..-..-.-----.-..--.--
.---.-.--...-..-...-.---.--.--..-.---.-..-...-..-.--.---.-.---.--..-...-..-...-
..-.--..---.-..--.--..-..-.--...-..-..-..--.--..-.--..-.--..-..--...-.---.--.--

See also

Interpreter

  • Common Lisp implementation of the Cerberus programming language. Routines are provided to also interpret its wimpmode equivalent Tiangou.