Array Literals
An entire array may be written as a literal provided it appears where a known array type expression is expected. For a one dimension array the syntax is as follows :-
arraylit ::= [ expr [[ , expr ]] ]
For a multi-dimension array. The first index uses the above syntax but with the expressions being replaced with array literals for each row. If you assigning to fixed size array then the number of expressions must match the dimension. If the target is an open array then any number of expressions can be used.
An example should make this clearer :-
Type MyArrayType = Number[1 To 2, 1 To 4]; Program() MyArrayType array = [ [1, 2, 3, 4], [10, 20, 30, 40] ]; Begin [= this should output 30 =] Output array[2, 3]; End;
If there is a third dimension then each value will be replaced by a literal array of the length of the third dimension. And so on.
Indexing Operator
The above example has already illustrated how array indexing works. The general syntax is :-
arrayexpr ::= expr [ expr [[ , expr ]] ]
The first expression should yield an array of known type. The other expressions give the indexes to use. There should as many expressions as there are dimensions in the array type. If the count is incorrect a compile time error will be generated. If the runtime values of an actual index is out of range a runtime error will be generated.