REGXY
Two kinds of line, a test and a change, both made of a Perl regular expression.
Zzo38 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Zzo38 built REGXY on regular expressions. The program works on one string, which starts as the whole input. Each line either tests the string and jumps, or changes the first match. When the program runs past its last line, the string is printed.
Read the story
The implementation is itself a REGXY program. It turns a REGXY program into Perl, and given its own source it prints the 11 lines of Perl that the specification shows as the implementation.
The machine
| Line | Does |
|---|---|
label/regex/target | If the regex matches, go on at the line called target |
label/regex/substitute/ | Replace the first match; $1 and ${1} are groups |
Patterns are Perl's with the s flag, so . also matches a line feed and $ matches at the end and before a line feed that ends the string. An empty pattern reuses the last one that matched. A slash inside a pattern or a substitute needs a backslash.
Example
The reverse marks the end with _, then moves the first character behind the mark until nothing is left in…
The reverse marks the end with _, then moves the first character behind the mark until nothing is left in front of it.
The 99 bottles builds the numbers 99 down to 0 from the digits, then writes a verse for each of the 100 numbers in a loop of two lines.
Patterns it teaches
- String rewriting: one string, rewritten line by line, and the compiler to Perl is such a rewrite too.
Further
See also
Unknown year
String-rewriting paradigm
Write your own in Run Convert a program from REGXY
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: regxy.
Command line
shib run regxy -e 'a/$/_/
b/(.)(.*)_/$2_$1/
c/(.)(.*)_/b
d/_// ' --input 'stressed'shib manual regxySource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/regxy.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org