Literals are either variables or constants.
Variables start with the letter 'x' and are followed by a natural number, i.e. (x0, x1, x2, ...). Variables starting with any different letter will not be recognized as such by the parser.
Depending on the number of parameters for your program, the first n variables after x0 will be assigned with the corresponding values. Let's say your program needs 3 parameters. The three values typed into the parameter field will be assigned to the variables x1, x2, x3 accordingly. x0 has the function of the return value (the result of your program). The remaining variables (x4, x5, x6, ...) can be used freely.
After parsing, variables will have the prettyfied form "X i" for i in 0, 1, 2, ... .
If not defined, variables are initialised with the value 0.
Since the parser is based on the set of natural numbers (0, 1, 2, ...), constants are limited to these numbers.
After parsing, constants will have the prettyfied form "C i" for i in 0, 1, 2, ... .
In the editor, any number which is not natural will not be recognized by the parser correctly and throw a parse error.
Terms are simple arithmetic expressions of literals.
After parsing, terms will be written in prefix notation, starting with the operation and followed by the operands.
Please note that arithmetic expressions are binary operations and therefore always need two operands.
Plus denotes the addition of two natural numbers, i.e. x2 + 1 parses to "Plus (X 2) (C 1)".
Minus denotes the subtraction of two natural numbers, i.e. x3 - x1 parses to "Minus (X 3) (X 1)".
Multiplication and division are not recognized by the parser. Nevertheless, you can write a program for these operations (see examples)
A program is one of the following constructs:
An assignment has the form variable = term.
Please note that terms are based on binary arithmetic expressions. As a consequence, it is not possible to assign a variable to a literal directly. Instead, transform the literal into a Term.
Example:
x0 = x1 + 0
Loop programs begin with the keyword "Loop" and end with the keyword "End". They have the following form:
Loop literal Do
program (subroutine)
End
Example:
Loop x3 Do
x4 = x1 + x2;
x0 = x4 - 1
End
The literal between the "Loop" and the "Do" keyword indicates the number of iterations of the subroutine. If the literal has a value smaller than or equal to zero, the subroutine won't be executed.
While programs begin with the keyword "While" and end with the keyword "End". They have the following form:
While variable > 0 Do
program (subroutine)
End
Example:
While x1 > 0 Do
x0 = x0 + 1
End
The condition between the "While" and the "Do" keyword has to be in the form "variable > 0". Any condition having another form will result in a parse error. The "End" keyword indicates the end of the subroutine.
Check for other conditions by making use of additional variables and the arithmetic operations addition or subtraction. If you want to check x1 > x2, for example, introduce a new variable x3 = x1 - x2 and check whether x3 > 0 since x3 > 0 implies that x1 > x2.
In order to chain programs and execute them in sequence, they have to be separated by a semicolon.
Example:
While x2 > 0 Do // Header for while program w1
x4 = x2 + 0; // Assignment, w1 subroutine
x0 = x1 + 0; // Assignment, w1 subroutine
Loop x1 Do // Header for loop program l1
x1 = x1 - x2 // Assignment, l1 subroutine
End // End of l1
End; // End of w1
x0 = x1 + 0 // Assignment
Line comments can be indicated with "//" at the beginning of a new line. Comments will be ignored by the parser.
Parse Errors contain information regarding what the parser read and what the parser did expect to read. Additionally the error contains information about the location in the source code.
Example:
This error message states that there was an error in your code at sourceLine = Pos 1 and pstateTabWidth = Pos 8. It further contains the information that it found the character 'a' and was expecting the character 'x'.
The error was caused by defining a variable that was starting with 'a' instead of 'x':
While a1 > 0 Do
x2 = x2 + 1
End
In order to avoid endless loops, a timeout was set in place. Since endless loops are errors in semantics, this type of error can't be checked by the parser and must therefore be caught manually. Code can be run for 5 seconds before being interrupted by a timeout error.
This error was caused by running the following example:
While x1 > 0 Do
x1 = x1 + 1
End
The parser has just read a part of the programm and not everything written into the editor.
Did you forget a semicolon? Different programs have to be separated by semicolons in order to run them in sequence.