TypeDeclaration = IdentDef "=" Type.Examples:
Type = Qualident | ArrayType | RecordType | PointerType
| ProcedureType.
Table = ARRAY N OF REAL
Tree = POINTER TO Node
Node = RECORD
key: INTEGER;
left, right: Tree
END
CenterTree = POINTER TO CenterNode
CenterNode = RECORD (Node)
width: INTEGER;
subnode: Tree
END
Function = PROCEDURE(x: INTEGER): INTEGER
1. BOOLEAN the truth values TRUE and FALSETypes 3 to 5 are integer types, types 6 and 7 are real types, and together they are called numeric types. They form a hierarchy; the larger type includes (the values of) the smaller type:
2. CHAR the characters of the extended ASCII set (0X .. 0FFX)
3. SHORTINT the integers between MIN(SHORTINT) and MAX(SHORTINT)
4. INTEGER the integers between MIN(INTEGER) and MAX(INTEGER)
5. LONGINT the integers between MIN(LONGINT) and MAX(LONGINT)
6. REAL the real numbers between MIN(REAL) and MAX(REAL)
7. LONGREAL the real numbers between MIN(LONGREAL) and MAX(LONGREAL)
8. SET the sets of integers between 0 and MAX(SET)
LONGREAL >= REAL >= LONGINT >= INTEGER >= SHORTINT
ArrayType = ARRAY [Length {"," Length}] OF Type.
Length = ConstExpression.
A type of the form
ARRAY L0, L1, ..., Ln OF T
is understood as an abbreviation of
ARRAY L0 OF
ARRAY L1 OF
...
ARRAY Ln OF T
Arrays declared without length are called open arrays. They are restricted to pointer base types (see 6.4), element types of open array types, and formal parameter types (see 10.1). Examples:
ARRAY 10, N OF INTEGER
ARRAY OF CHAR
RecordType = RECORD ["("BaseType")"] FieldList {";" FieldList} END.
BaseType = Qualident.
FieldList = [IdentList ":" Type ].
Record types are extensible, i.e. a record type can be declared as an extension
of another record type. In the example
T0 = RECORD x: INTEGER END
T1 = RECORD (T0) y: REAL END
T1 is a (direct) extension of T0 and T0 is the (direct) base type of T1 (see App. A). An extended type T1 consists of the fields of its base type and of the fields which are declared in T1. All identifiers declared in the extended record must be different from the identifiers declared in its base type record(s).
Examples of record type declarations:
RECORD
day, month, year: INTEGER
END
RECORD
name, firstname: ARRAY 32 OF CHAR;
age: INTEGER;
salary: REAL
END
PointerType = POINTER TO Type.If p is a variable of type P = POINTER TOT, a call of the predeclared procedure NEW(p) (see 10.3) allocates a variable of type T in free storage. If T is a record type or an array type with fixed length, the allocation has to be done with NEW(p); if T is an n-dimensional open array type the allocation has to be done with NEW(p, e0, ..., en-1) where T is allocated with lengths given by the expressions e0, ..., en-1. In either case a pointer to the allocated variable is assigned to p. p is of type P. The referenced variable p^ (pronounced as p-referenced) is of type T. Any pointer variable may assume the value NIL, which points to no variable at all.
ProcedureType = PROCEDURE [FormalParameters].