Documentation du démonstrateur

The demonstrator's script language is called 'HSL'. It is a minimalist language providing facilities for accuracy analysis. The language will evolve over time to become easier to use, as it lacks many features yet.


HSL is a statically typed language. It provides two types:
- integer
- float

The integer type is a signed integer encoded on 64 bits.
The float type is defined at run time. It can be a primitive type (float / double / long double in C), or a multi-precision floating point format.
HSL also provides arrays (including multidimensional arrays). More on that in the variable declaration section below.


A variable can only have alphanumeric characters, plus the underscore character. The only restriction is that it must not begin with a numerical character. Variable names are case sensitive, and must be unique.
All variables are initialized to 0 by default.
Once declared, variables exist for the lifetime of the program.

Variable declaration:
Declaring a variable is just like in C. Just simply write the type followed by the variable name.
float a;
integer b;
By default, variables are initialized to 0. You can initialize a variable when declaring it:
float a := 3.5;
integer b := 8;
To declare an array, just indicate the dimensions next to the type name.
float[5] array;
float[10, 5] matrix;
integer[3, 3, 3] three_dimensional_array;

You can't initialize arrays at declaration time.
Arrays are index from 0.
To access to elements of the arrays, just use the operator [] like this:
array[0] := 3.6;
array[4] := 10.1;
array[5] := 0; # ==> error: index out of bounds
matrix[0, 4] := 33.5;
matrix[b, 0] := 66.1;
three_dimensional_array[0, 0, 1] := 5;


Here is the list of the operators, by order of increasing precedence:
Operator NameOperatorNotes
Affectation operator:=
Logical ORorUnlike C/C++, operator || does not exist
Logical ANDandUnlike C/C++, operator && does not exist
Equal and Not Equal==, !=
Greater/Lesser, Greater or equal, Lesser or equal<, >, <=, >=
Operator addition and subtraction+, -
Operator multiply, divide and modulo
*, /, %, modModulo can be written just '%' or in letters: 'mod'
Unary operator + and -+, -

Control structures

As there is no boolean type, any value evaluated to 0 is considered as false. Any other value than 0 is considered true.
If you assign a variable to the result of a boolean operation, it will receive the value of 0 (if false) or 1 (if true).

If statement

The if statement syntax is:
if cond_expr: statement_if_true else: statement_if_false
The whole else part is optional. You can have multiple statements if you place them in a block with { }.
A dandling else refers to the latest if.

if a == 0:
  b := c;
  b := c / a;
if a + 3 < 4: {
  b[a] := 5;

For statement

The for statement syntax is:
for variable from first to last step s: statement
The step part is optional.

for b from 0 to 4 step 1:
  array[b] := a + b;
# This is the equivalent in C: 
# for (b=0; b<=4; b = b + 1)
#   array[b] = a + b;
for b from 0 to 4:
  array[b] := a + b;
# Same example, but with an implicit step of 1
for b from 100 to 0: {
  array[b] := a + b;
# There is an implicit step of 1. In this case
# there won't be a single iteration done.
# The variable b will still be initialized to
# 100, as it happens before the loop condition.
for b from 100 to 0 step -1: array[b] := a + b;
# This is the equivalent of C:
# for (b = 100; b >= 0; b -= 2)
#   array[b] = a + b;

You can't have a step of 0, and you can't modify the iteration variable inside the loop.

While statement

The while loop has the following syntax:
while cond_expr: statement

while a < 3:
  a := a + 0.1;
while a != 3: {
  a := a + 1;
while a * b + 15 <= 30 * a + 52 * b: {
  a := a + 1;
  b := b + 1;

Export statement

You have to export variable's values in order to analyze them, and draw a chart. There are two kind of exports: indexed exports and standalone exports.
Indexed exports are mostly used when you want to export a variable inside a loop. You must specify the index, which must be unique. Non-unique indexes will just overwrite the previous exported value.

float a;
integer i;
for i from 0 to 100: {
  export i, a; # This is an indexed export.
  a := a + 0.1;
export a; # This is a standalone export.


You can't define functions, but there are some predefined functions you can use at your convenience.
Most of them are mathematical functions functions of C, with correct rounding.

float random()
Returns a float number between 0 and 1. It is computed by dividing a random number by its largest possible value (which is 2^31 - 1).

void  random_seed_set(integer s)
Set the seed of the random number generator.

integer isInf( float x)
Returns 1 if x is infinite (regardless of the sign). Returns 0 otherwise.

float   getInf()
Returne positive infinity. You can negate it with the unary operator- .

integer isNaN( float x)
Returns 1 if x is Not a Number. Returns 0 otherwise.

float   getNaN()
Returns Not a Number.

float   getConstPI()
Returns the constant PI.

The rest of the functions are mathematical functions:
float acos ( float x)
float asin ( float x)
float atan ( float x)
float atan2( float y, float x)

float sin( float x)
float cos( float x)
float tan( float x)

float sinh( float x)
float cosh( float x)
float tanh( float x)

float asinh( float x)
float acosh( float x)
float atanh( float x)

float exp  ( float x)
float exp2 ( float x)
float log  ( float x)
float log2 ( float x)
float log10( float x)

float pow ( float x, float y)
float sqrt( float x)

float abs  ( float x)
float ceil ( float x)
float floor( float x)


All text from the beginning of the '#' symbol to the end of the line is a comment.


Please, don't forget that this is just a demonstrator. It is not designed for huge and complex calculus. In order to alleviate the load of our servers, the number of iterations and the length of programs is limited.