Data

Data

There are three kinds of data: variables, persistents and constants.

Except for predefined data and loop variables, all data used must be declared.

Data scope

The scope of data denotes the area in which the data is visible. The optional local directive of a data declaration classifies data as local (within the module), otherwise it is global. Note that the local directive may only be used at module level, not inside a routine.

Example: LOCAL VAR num local_variable;

VAR num global_variable;

Data declared outside a routine is called program data. The following scope rules apply to program data:

Program data may not have the same name as other data or a routine in the same module. Global program data may not have the same name as other global data or a routine in another module. A persistent may not have the same name as another persistent in the same program.Data declared inside a routine is called routine data. Note that the parameters of a routine are also handled as routine data. The following scope rules apply to routine data:

See the example in Figure :

 Example: The following data can be called from routine e:

Module1: Data c, d.

Module2: Data a, f, g, e1.

The following data can be called from routine h:

Module1: Data d.

Module2: Data a, f, g, h1, c.

Routine data may not have the same name as other data or a label in the same routine.

Variable declaration

A variable is introduced by a variable declaration.

Example: VAR num x;

Variables of any type can be given an array (of degree 1, 2 or 3) format by adding dimensional information to the declaration. A dimension is an integer value greater than 0.

Example: VAR pos pallet{14, 18};

Variables with value types may be initialised (given an initial value). The expression used to initialise a program variable must be constant. Note that the value of an uninitialized variable may be used, but it is undefined, i.e. set to zero.

Example: VAR string author_name := "John Smith";

VAR pos start := [100, 100, 50];

VAR num maxno{10} := [1, 2, 3, 9, 8, 7, 6, 5, 4, 3];

The initialisation value is set when:

Persistent declaration

Persistents can only be declared at module level, not inside a routine, and must always be given an initial value. The initialisation value must be a single value (without data or operands), or a single aggregate with members which, in turn, are single values or single aggregates.

Example: PERS pos refpnt := [100.23, 778.55, 1183.98];

Persistents of any type can be given an array (of degree 1, 2 or 3) format by adding dimensional information to the declaration. A dimension is an integer value greater than 0.

Example: PERS pos pallet{14, 18} := [...];

Note that if the value of a persistent is updated, this automatically causes the initialisation value of the persistent declaration to be updated.

Example: PERS num reg1 := 0;

...

reg1 := 5;

After execution, the program looks like this:

PERS num reg1 := 5;

...

reg1 := 5;

It is possible to declare two persistents with the same name in different modules, if they are local within the module (PERS LOCAL), without any error being generated by the system (different data scope). But note the limitation that these two persistents always have the same current value (use the same storage in the memory).

Constant declaration

A constant is introduced by a constant declaration. The value of a constant cannot be modified.

Example: CONST num pi := 3.141592654;

A constant of any type can be given an array (of degree 1, 2 or 3) format by adding dimensional information to the declaration. A dimension is an integer value greater than 0.

Example: CONST pos seq{3} := [[614, 778, 1020],

[914, 998, 1021],

[814, 998, 1022]];

Initiating data

The initialisation value for a constant or variable can be a constant expression.

The initialisation value for a persistent can only be a literal expression.

Example: CONST num a := 2;

CONST num b := 3;

! Correct syntax

CONST num ab := a + b;

VAR num a_b := a + b;

PERS num a__b := 5;

! Faulty syntax

PERS num a__b := a + b;

Storage Class

The storage class of a data object determines when the system allocates and de-allocates memory for the data object. The storage class of a data object is determined by the kind of data object and the context of its declaration and can be either static or volatile.

Constants, persistents, and module variables are static, i.e. they have the same storage during the lifetime of a task. This means that any value assigned to an persistent or a module variable, always remains unchanged until the next assignment. Routine variables are volatile. The memory needed to store the value of a volatile variable is allocated first upon the call of the routine in which the declaration of the variable is contained. The memory is later de-allocated at the point of the return to the caller of the routine. This means that the value of a routine variable is always undefined before the call of the routine and is always lost (becomes undefined) at the end of the execution of the routine.In a chain of recursive routine calls (a routine calling itself directly or indirectly) each instance of the routine receives its own memory location for the "same" routine variable - a number of instances of the same variable are created.

Syntax

Data declaration

<data declaration> ::=

[LOCAL] ( <variable declaration>

| <persistent declaration>

| <constant declaration> )

| <comment>

| <DDN>

Variable declaration

<variable declaration> ::=

VAR <data type> <variable definition> ’;’

<variable definition> ::=

<identifier> [ ’{’ <dim> { ’,’ <dim> } ’}’ ]

[ ’:=’ <constant expression> ]

<dim> ::= <constant expression>

Persistent declaration

<persistent declaration> ::=

PERS <data type> <persistent definition> ’;’

<persistent definition> ::=

<identifier> [ ’{’ <dim> { ’,’ <dim> } ’}’ ]

’:=’ <literal expression>

Constant declaration

<constant declaration> ::=

CONST <data type> <constant definition> ’;’

<constant definition> ::=

<identifier> [ ’{’ <dim> { ’,’ <dim> } ’}’ ]

’:=’ <constant expression>

<dim> ::= <constant expression>