Strvar
Strvar is an esolang by User:PythonshellDebugwindow based on string rewriting.
Syntax
Every non-blank line in a valid Strvar program is either a variable definition or a lone string literal. Variable definitions look like this:
myVar = "myString";
Lone string literals look like this:
"myString";
A lone string literal on a line will be output followed by a newline. Valid escape codes in strings are \r \n \" \t \xhh
. Variables can be reassigned a new (or the same) value. Variable names must match the regex [^\s"#;=]+
. Spaces outside of strings are ignored, including in variable names, so at assignment, "my var" and "myvar" are the same variable, both changed to "myvar". Comments are denoted by a #
, are ignored, and last until end-of-line.
String rewriting
Each time a string literal is evaluated, it is checked to see if it contains any variable names. If it does, then the following actions take place:
- The first occurrence of a variable name in the string is replaced with the variable's value.
- If there is still a variable name in the string, then repeat the process.
This will result in an infinite loop if a variable used in a string is set to its own name, as it will always contain the name (and value) of the variable.
Examples
Hello, World!
"Hello, World!";
Showing off more features:
h = "Hello,"; w = "World!"; "h w";
The string ends up with infinitely many "orld!"
s on the end, and never gets printed out because the program goes into an infinite loop:
h = "Hello,"; w = "world!"; "h w";
Truth-machine
Change "0"
to "1"
for input 1. Loops forever for 1 = "1";
, prints 0 for 1 = "0";
.
1 = "0"; "1";
Interpreter test cases
This code:
a = "b"; b = "c"; "a";
should print "b", and this code:
b = "x"; a = "b"; b = "y"; "a";
should print "x".
Counter
This program prints the string “1 2 3”:
one = "1"; two = "one 2"; three = "two 3"; "three";
Resources
- An unfinished interpreter written in NodeJS
- Common Lisp implementation of the Strvar programming language.