run
help
1
run
compile
variable names
x := c, x:= x, ..
*
/
%
==
<,>
<=,>=
IF
ELIF
help
1
Code
Help
All standard WHILE constructs can be used.
Variables can have any name of the pattern [a-zA-Z][a-zA-Z0-9_]*.
x0
is the result variable.
Some common extensions are supported aswell.
Assignment
In addition to
+
and
-
there are
*
,
/
and
%
operators.
Assignments can take the following forms (where c is a literal, and x is a variable):
x := c
x := x
x := c + c
x := x + x
x := x + c
x := c + x
WHILE Statement
WHILE
statements support any comparison with the operators:
==
,
!=
,
<
,
>
,
<=
and
>=
IF Statement
IF
statements, with optional
ELIF
s and
ELSE
are supported.
DEBUG
Use
DEBUG
to output the value of variables:
x0 := 1; n := 4; LOOP n DO x0 := x0 * 2; DEBUG x0 END
You can debug multiple variables in one line:
DEBUG a, b, c
Variables
Declare variables with the var keyword:
var a = 2 var b = 4 * a
Variables (and expressions) can have one of two types: nat (natural number) and bool (boolean).
The type of a variable gets infered, but may be set explicitly:
var x: nat = 2
Variables can be assigned to:
x = 3
There is a special variable result that represents the final result.
It does not need to be declared (it is initialized with 0), but otherwise it can be used like any other variable.
Expressions
Expressions can use the operators:
+
,
-
,
*
,
/
,
%
,
==
,
!=
,
<=
,
>=
,
<
,
>
,
or
,
and
Example:
var x = 10 var y: bool = 1 + 4 < x and (true or x == 0)
There is also some syntax sugar for assignment:
+=
,
-=
,
*=
,
/=
,
%=
x += 2
is equivalent to
x = x + 1
The same principle applys to the other operators.
If Statement
Expamples:
if x < 3: result = 1
if a * b >= c: a += c elif result == 0: a = 1 result = b else: a = 2
For Loops
Expample:
for i in 0 .. a + 2: result += i
This for loop will count from 0 to a + 1 (so the upper bound is exclusive).
The iterration value can be ignored by using a _:
result = 1 for _ in 0 .. 3: result *= 2
While Loops
Expample:
result = 1 while result <= 42: result *= 2
Comments
Comments start with a #
# find the smallest power of 2 thats bigger than 42: result = 1 while result <= 42: result *= 2 # get next power of 2
Debug
Add debug command to output variables values when running:
result = 1 while result <= 42: result *= 2 debug result
You can output multiple variables at once:
debug x, y