![]() |
![]() |
![]() |
![]() |
(..Declaration Part..) | Contents | Index | (Statement Part..) |
All the rest of the declaration part is provided for variables and symbolic constants.
|
You may skip this part in your program, if you have no need of these structures. Furthermore you are rather free in how to order the single devices. But take care that all the objects used to declare a symbolic constant are already defined.
Once we have decided to use variables in our program, we have to declare them first:
|
Each variable declaration unit starts with the keyword
and is followed by entries of the form
Legal variable types are INT, STRING, BOOL, and CELL, while IdentifierList contains the names of variables, which should be of the chosen type. There can be as many entries as we want.
All defined variables are initialized by SCARLET. Integer variables
get the value 0, boolean the logical
value TRUE and string
variables the empty string "". Variables of type CELL are
initialized by handling the single registers as string or integer
variables respectively.
... VAR INT counter; STRING name1, name2; INT result; VAR BOOL is_enough; CELL a_state; ...
|
Now we arrive at the principle of symbolic constants, already introduced. Like the declaration part for variables, the one for symbolic constants begins with a special keyword
It is followed by an arbitrary amount of entries of the form
where Identifier means
the name of the constant to be declared
and Expression the value it should have.
(Remember that IntIdentifier, StringIdentifier, ...
are just Identifiers.)
Depending on what we choose
for Expression
(IntExpression,
StringExpression,
BoolExpression, or
CellExpression),
the constant itself will be of
one of the types INT, STRING, BOOL, or CELL.
It is allowed to use variables as well as other symbolic constants to form Expression, but only if they are already declared above.
Running the program later, SCARLET will first - according to their order
within the source code - evaluate all the expressions
on the right side
of each equal sign to get constant expressions, and will finally store them
internally. SCARLET does this only once a runtime.
Such an evaluation leaves
constant expressions unchanged,
symbolic constants are
replaced by their (already established) value,
variables are replaced by
their present value (which is nothing else than their initialization value).
Expressions with
function calls and
operators are reduced according to the
common rules explained in chapter 2, and
CellExpressions are
finally handled by evaluating the expressions in the single registers
starting at the left.
It is important to notice that VOID is treated like a constant expression.
That is the reason why it can still
be a register contents of a symbolic
constant after having passed the evaluation.
Such a constant expression - as a result of this evaluation procedure - is
now available under the name Identifier, that means, whenever there
appears the name of this constant within the following source code,
it will be replaced by its (constant) value.
Its declaration causes a symbolic constant to be an object of the same type as
the value it got.
... REGISTER INT num; CONST max = 2147483647; a_number = rand(0,100); is_greater = a_number > 50; VAR CELL a_cellvar; CONST initialized_cell = a_cellvar; /* ={0} */ crypt = "<*@_"+ itos(a_number); ...
![]() |
![]() |
![]() |
![]() |
(..Declaration Part..) | Contents | Index | (Statement Part..) |