esolang

PDAsephone

A pushdown automaton is not Turing complete. A stack of them that you can copy and swap is.

BoundedBeans · Turing complete: yes · ●●● hard · esolangs.org

Tested with 7 known programs · Test method

Run it

Expected: Hello world!

The idea

BoundedBeans built PDAsephone on pushdown automata, the machines that can match brackets and do little else. In PDAsephone they are values. A program pushes fresh automata onto a stack, gives them transitions one at a time, feeds them characters, copies them and swaps them. There is no arithmetic and no conditional. To add two digits you build an automaton with a transition for every pair, which the specification calls the value of a Turing tarpit.

The machine

There are two stacks, one of characters and one of automata. A fresh automaton is in state 0 with an empty stack and no transitions, and its stack reads as a line feed when empty.

CommandDoes
"c _Push the character c, or a line feed
, .Read a character; pop and print one
: / $Copy, swap or drop characters
@ ; \ #Push a fresh automaton; copy, swap or drop automata
%Pop six characters and add a transition to the top automaton
!Pop a character and run the top automaton on it
v ^Move a character onto the automaton's stack, or back off it
\|Pop a letter and jump to it, ahead for a capital, back for a small letter

% pops u, v, w, x, y and z. The transition says that on input u in state v with w on top of its stack, the automaton pops if x is not 0, pushes y unless y is a line feed, and goes to state z. So a program pushes the six in the order z y x w v u. Every letter but u to z is a label, except one that a " pushes. , ends the run at the end of the input, which the specification leaves open.

Example

The first Hello world pushes the text backwards and prints twelve times, so .

The first Hello world pushes the text backwards and prints twelve times, so . has to pop.

Expected: cat

The cat jumps back to its first a. The second a is pushed by ", so the jump passes over it.

The adder reads two digits from 0 to 3 onto an automaton's stack. The first ! moves it into the state of the top digit, the second pops the other digit and pushes the sum, and ^. prints it.

Expected: 5

Patterns it teaches

Further

Stack-based

Write your own in Run Convert a program from PDAsephone

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run pdasephone -e 'a,."a|' --input 'cat'
shib manual pdasephone

Source

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

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

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