An example of an array definition is
type memory is array (range 0 to 65535) of integer;
A type definition can also use positions with greater than one dimension.
For example, the truth table of the xor function of two variables can
be thought of as a two-dimensional array of 0 and 1 values.
The index of a two-dimensional array has two values, one for the position
in one direction and the other for the position in the other direction.
We might write the two dimensional array of the xor function as
0 1
1 0
If the positions are numbered left to right from 0 to 1 and top to
bottom from 0 to 1, then the value at any index position is equivalent
to the result of applying the xor function to the two values in the index.
An index is indicated as a list of values separated by commas and enclosed
by parentheses. The valid indices for the xor array and the values at those
positions are
(0,0) = 0
(0,1) = 1
(1,0) = 1
(1,1) = 0
which looks much like a truth table! Arrays are a natural way to represent
functions of variables that only have a small number of values
(like bit functions). For a function of N variables an N-dimensional array
can be used with each variable represented by one value of the index.
Any function of two bits could be represented with an object of the
following array type
type two_bit is array (bit range '0' to '1', bit range '0' to '1') of boolean;
The gammar rule for an array definition is:
unconstrained-range : type RANGE "<>"
index-constraint : "(" discrete-range {"," discrete-range} ")"
discrete-range : subtype | range
constrained-array-type :
array index-constraint OF subtype
unconstrained-array-type :
array "(" unconstrained-range {"," unconstrained-range} ")"
OF subtype
array-type-definition : constrained-array-type | unconstrained-array-type
An unconstrained array type is an array type that has an unspecified range of values in its index. An object can not be declared an unconstrained array type because there is no way to know its size. However, the unconstrained array type can be used to declare subtypes that constrain the array by specifying the ranges of its index. Bit_vector and string are built-in unconstrained array types. Their definition is
type bit_vector is array (natural range <>) of bit; type string is array (positive range <>) of character;