esolang

T-rexes

Regular expressions that can write, and step back. That is enough for a Turing machine.

Xia Li-yao, 2024 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: bit

The idea

Xia Li-yao made T-rexes, Turing regexes, in 2024. A regular expression reads its input once, left to right. A T-rex runs on a tape instead, and it may also write a symbol and move left. The head is called the T-rex and the program the tale.

Read the story

With only checks and moves to the right, a tale is an ordinary regular expression. b(a|i)t becomes b?>((a?|i?)>)t?>, and it matches bat and bit but not bot. Writing and moving back are what make it Turing complete. The specification translates Smallfuck into it, with a guarded loop that repeats while the cell holds 1.

Like a regular expression, a tale is nondeterministic. 0!|1! may write either symbol. This implementation searches for one run that succeeds, trying the left of every | first and leaving every * before it takes one more round. So (1!>)* writes no 1 at all, and (>)*1? stops on the first 1 it comes to.

The machine

TaleDoes
s!Write the symbol s
> <Move the T-rex right or left
s?Succeed only if the cell holds s
e0 e1Both, one after the other
e0\|e1One or the other
e*e any number of times
s~ + -An extension in the specification; not s, and step the cell up or down

The input is the tape, with the T-rex on its first symbol, and every other cell holds 0. When a run succeeds, the tape is printed from the first input cell to the last and as far out as any cell that is not 0. When none succeeds, nothing is printed.

Example

The second tale is Smallfuck's *, which flips a bit.
Expected: 1
Expected: 0011

The second tale is Smallfuck's *, which flips a bit. The third counts in binary with the lowest bit first. It turns each 1 into 0 until it finds a 0, which becomes 1, so 11 becomes 12.

Patterns it teaches

  • Nondeterminism: a tale describes many runs, and one that works is enough.
  • Turing tarpit: Smallfuck fits inside with only a guarded loop.

Further

Nondeterministic

Write your own in Run Convert a program from T-rexes

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: t-rexes.

Command line

shib run t-rexes -e '(0?1!|1?0!)' --input '0'
shib manual t-rexes

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/t-rexes.js

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

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