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:
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.
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.
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";
"1" for input 1. Loops forever for
1 = "1";, prints 0 for
1 = "0";.
1 = "0"; "1";
Interpreter test cases
a = "b"; b = "c"; "a";
should print "c", and this code:
b = "x"; a = "b"; b = "y" "a";
should print "x".
- An unfinished interpreter written in NodeJS