SRL++
Every line is one call to Python's re.sub, from one named string into another.
MattiDragon · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
MattiDragon made String Replacement Language++ with an interpreter in Python. Data lives in banks, named strings that start empty. A line takes the string in one bank, replaces every match of a regular expression and stores the result in another bank, or the same one.
Read the story
Three banks are special. Writing io prints and reading it takes a line of input. _ reads as empty and swallows what is written to it. Writing a number to pointer jumps to that line, and that is the only control flow there is.
The machine
A line is regex source destination replacement, split at its first three spaces.
| Part | Does |
|---|---|
(.*) | A Python regex, without spaces |
io | The bank to read |
num | The bank to write |
\1 bottles | The replacement, which may hold spaces; \1 is a group and \n a line feed |
# ... | A comment line; it still counts as a line |
Lines are counted from 1. A negative pointer ends the run, and so does running past the last line.
Example
The specification warns that .* matches twice on a string that is not empty, once for the text and once…
The specification warns that .* matches twice on a string that is not empty, once for the text and once for the empty end.
The truth machine turns the input into the line to jump to. On 0 it jumps to line 7 and prints 0 once. On 1 it jumps to line 5, and lines 5, 6, 3 and 4 print 1 forever.
The 99 bottles program counts with a row of 99 Is and turns it into digits with 23 lines of replacements, ten Is to an X and the Xs to a tens digit.
Patterns it teaches
- String rewriting: every step rewrites a whole string.
Further
See also
Also in Rewriting
Write your own in Run Convert a program from SRL++
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: srl.
Command line
shib run srl -e '(.*) io input \1
0 input input 7
1 input input 5
(.*) input pointer \1
.* _ io 1
.* _ pointer 3
.* _ io 0' --input '0'shib manual srlSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/srl.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org