rulesystem

From Esolang
Jump to navigation Jump to search

rulesystem [sic] is a programming language based on a unique data format known as Rules. It is currently still a WIP.

World

The "World" of rulesystem is composed of a series of lines arranged in a grid pattern. Each line may be full or empty. Full lines display black, and empty lines display white (the background also displays white). Different instructions (see Rules) may be able to modify whether a given line is full or empty. The dimensions for the world are 100x100 (however different interpreters may have different allowed sizes), and if you exit the world, an error will be thrown.

Rules

Rules are a string of the following five characters.

Character Operation
R Move Right
U Move Up
L Move Left
E Move Down
(Space) Do Nothing

Rules can either be written (meaning that the line at the cursor will be set to full before every movement), erased (meaning that the line at the cursor will be set to empty before every movement) or moved (meaning that the cursor is simply moved by the rule and no drawing takes place). Rules can also be either infinite (meaning the loop after reaching the end) or finite (meaning they finish execution once reaching the end).

Basic Syntax/Commands

All lines in rulesystem must end with a semicolon. All instructions must be typed in lowercase, all rules must be typed in uppercase, and variables may be in any case.

Delimiting Rules

Rules are delimited by double quotes. (e.g. "RELU")

Comments

Comments are opened and closed with | (e.g. |I am a comment!|)

Variables

Variables are defined with a name, which may consist of any character, and are case-sensitive (myRule is different from myrule). All variables are global. The two types of variables in rulesystem are finite and infinite (which refer to finite and infinite rules). When instantiating variables, the variable type must come first, then the variable name. Variables can be defined uninitialized, or they can be defined initialized with a rule. For example:

finite rule1 = "RULE"; |This initializes a finite rule containing "RULE"|
finite rule2; |This defines an unitialized rule|

Write (And Other Rule Commands)

The syntax to write a rule is this:

finite rule = "RULE"; |Define <rule> as "RULE"|
write rule; |write the rule to the screen|
write "EELU"; |You can also write a rule directly without the use of variables. Whenever this happens, it will be treated as a finite rule.|

The syntax for move and erase work similarly, just replace write with erase or move

Input

The input command prompts the user for one key of input, which may only be a valid rule character. If any other character is typed, it is ignored and the execution only returns to normal once a valid rule. While the user is prompted for an input, the background turns green, and it returns to being white once the user has selected their input. The following takes one character of user input and writes it. (Note: The variable must be defined before it is used in an input instruction.)

finite i;
input i;
write i;

Loops

The follow instruction can be used to create loops. follow defines the start of a loop, and is followed by a rule command (write, erase, or move), then by a rule definition or a variable, and the loop is terminated by the end instruction. The way a follow loop works is that for every iteration i, it executes the character at index i of the rule given to the follow loop, then executes all inner code. For example:

infinite l = "LUL";
follow write l;
  write "URU";
end;

This will infinitely loop over rule l, which contains the rule "LUL". Whenever it executes a character of l it will perform the write command on it. And every time a character is executed in l, it will also execute URU. This code is equivalent to the following loopless code:

infinite l = "LURUUURULURU";
write l;

Until

A follow loop may be continued until a certain event happens. This is notated with the until keyword. The existing events are:

  • collision - This happens when when a line is attempted to be set when it currently holds the same value as what it is trying to be set as. (For example, trying to write over a filled line, or trying to erase over an unfilled line)
  • key - This happens whenever the user presses any key.

Whenever the specified event happens, the remainder of the code within the loop will be executed and then it won't return back to the follow once it reaches the end

Example:

infinite r = "UURU"
follow write r until collision;
  write "L";
end;

If the until collision wasn't there, this code would run forever, but since it's there, the "R" in variable r will collide with the "L" that is being written, causing the loop to terminate prematurely.

Operations

There are three operations in rulesystem:

  • The set operation (=) sets a rule to another rule. For example: finite rule1 = "RUL"; sets the variable rule1 to "RUL"
  • The concatenation operation (+=) concatenates two rules. For example: finite rule1 = "EE"; finite rule2 = "ERE"; rule1 += "EE"; will concatenate "EE" (rule1) and "ERE" (rule2) and store it in rule1.
  • The flip operation (f=) replaces every character in the first rule that matches every other character in the second rule with the character after it. For example: finite flip = "RULE"; flip f= "RLLR" sets variable flip to "LURE" since it replaces every R with an L and every L with an R.
  • The root operation (r=) cancels out all lefts and rights with eachother, and all ups and downs with eachother. For example: finite rule1 r= "ULEERRR" will set rule1 to ERR, since the first U cancels out the first E (ULEERRR -> LERRR) and then the left cancels out the right (LERRR -> ERR).

Code Examples

Cat*

infinite nothing = " ";
finite i;
follow move nothing;
  input i;
  write i;
end

*This is a cat in the sense that it prints out whichever direction the user types. It does not print out what the user types as letters.

Hello World

This program writes "Hello World!" to the screen.

write "UUERUEE";
move "R";
write "UURLERLER";
move "RUU";
write "EER";
move "RUU";
write "EER";
move "R";
write "UUREEL";
move "RRR";
write "UUEERUUEERUU";
move "REE";
write "UUREEL";
move "RR";
write "UURELRER";
move "RUU";
write "EER";
move "RUU";
write "RERLELUU";
move "RRRU";
write "EE";
move "E";
write "E";

Interpreter

User:dorcelessness is currently working on an interpreter and compiler for the language.