RegexPL is a programming language where computation is based entirely on matching strings against regular expressions. The programming language was designed and implemented by Daniel Korsgård in May 2010.
The intention of the programming language was to show how a not too unreasonable programming language could be made, where computations consist entirely on mutation of character strings.
The author of the language was tired of seeing an increasing number of esoteric languages that are essentially copies of existing popular esoteric languages. The author therefore created this RegexPL based on a fundamentally and radically different kind of computation than existing esoteric languages.
RegexPL is a Turing complete programming language where strings are the only datatype. Only three basic operations are implemented, namely: function call, regex/string matching, and string concatenation. The syntactical constructs of RegexPL are fairly elaborate, structured, and readable, unlike most esoteric languages. As a result of the relatively complex grammar rules, refer to the RegexPL page (from the Wayback Machine; retrieved on 13 August 2015).
A RegexPL program consists of one or more function declarations. A function consists of a mix of test statements and return statements. Those statements consists of strings, names, index expressions, and concatenation expressions.
def Main() ! "Hello world"
def if_A_is_true(A) A /^true|TRUE$/ # Tests the string in parameter A against the regular expression /^true|TRUE$/ ! "Yay, A is true :D" # Return "Yay, A is true :D" if the previous test matched ! "Buhuu, A is not true :C" # Otherwise...
def hungry(Food1, Food2) Food1 /pancake|cookie/ Food2 /chocolate milk|soft drink/ ! "very" # Both tests matched ! "maybe" # Only first test matched ! "no" # First test did not match
def extract_number(Str) Str /([0-9]+)/ # Tests for and captures a number ! Str # If a number was found, it will be returned ! "" # If no number was found, empty string will be returned
Recursion and Concatenation
def extract_all_numbers(Str) Str /^[^0-9]*([0-9]+)(.*)$/ # Test for number, then capture first occurrence of a number and any text behind number ! Str "-" extract_all_numbers(Str) # Concatenate the found number with '-' and any following numbers ! ""
RegexPL programs are written in plain text files, either encoded as UTF-8 or ASCII. Currently there is only one known compiler - the original - which will perform parsing, semantical checking, conversion to internal byte code, and lastly execution of that byte code.
The computation approach of the language Thue is also based on text replacement, but in a much simpler way. The computational model of RegexPL was therefore already discovered in the year 2000. The property of Turing completeness of RegexPL was however discovered independently.
The basic computational model of RegexPL can be reduced to that of Thue.