A TYPE section introduces the name and set of values for a
user-defined type or schema definition and has one of the
following forms:
Syntax:
TYPE
{type-identifier = [[attribute-list]] type-denoter}
[[VALUE initial-state-specifier]];...
TYPE
{schema-declaration} [[VALUE initial-state-specifier]]
The 'type-identifier' is the identifier of the type being
defined.
The 'attribute-list' is one or more optional identifiers that
provide additional information about the type-denoter.
The 'type-denoter' is any legal Pascal type syntax.
The 'schema-declaration' is the declaration of a schema type.
The 'initial-state-specifier' is a compile-time expression that
is assignment compatible with a variable of the TYPE identifier
being defined. VSI Pascal initializes all variables declared to
be of this type with the constant value or values provided
(unless there is an overriding initial-state specifier in the
variable declaration).
Pascal requires that all user-defined type identifiers (except
base types of pointers) be defined before they are used in the
definitions of other types. A base type must be defined before
the end of the TYPE section in which it is first mentioned.
Example:
TYPE
Entertainment = ( dinner, movie, theater, concert );
Week_end = ( sat, sun ) VALUE sat;
Hours_worked = ARRAY[mon .. fri] OF INTEGER;
Salary = ARRAY[1 .. 50] OF REAL;
Salary_template( upper_bound : integer ) =
ARRAY [1..upper_bound] of REAL;
Pay = salary;
Ptr_to_hits = ^Hits;
Hits = RECORD
Title, Artist, Composer : VARYING[30] OF CHAR;
Weeks_on_chart : INTEGER;
First_version : Boolean;
END;
VAR
Week1, Week2 : Week_end;
Week3 : Week_end VALUE sun;
Salary_type2 : Salary_template( x );
In this example, 'Week1' and 'Week2' have initial values of sat,
as specified in the TYPE definition of 'Week_end'. 'Week3' has
an initial value of sun, because an initial value specified in
the variable declaration overrides any initial value specified
in the type definition. The 'Salary_template' schema has actual
discriminants of x, which indicates that the upper boundary of
'Salary_type2' will be determined at run time by a variable or
function call.