# Definition of terms

Integer types | SHORTINT, INTEGER, LONGINT
Real types | REAL, LONGREAL
Numeric types | integer types, real types

- Same types
- Equal types
- Type inclusion
- Type extension (base type)
- Assignment compatible
- Array compatible
- Expression compatible
- Matching formal parameter lists

## Same types

Two variables a and b with types Ta and Tb are of the same type if

1. Ta and Tb are both denoted by the same type identifier, or
2. Ta is declared to equal Tb in a type declaration of the form Ta = Tb, or
3. a and b appear in the same identifier list in a variable, record field, or formal parameter declaration and are not open arrays.

## Equal types

Two types Ta and Tb are equal if

1. Ta and Tb are the same type, or
2. Ta and Tb are open array types with equal element types, or
3. Ta and Tb are procedure types whose formal parameter lists match.

## Type inclusion

Numeric types include (the values of) smaller numeric types according to the following hierarchy LONGREAL REAL LONGINT INTEGER SHORTINT

## Type extension (base type)

Given a type declaration Tb`= RECORD (`Ta`)... END`, Tb is a direct extension of Ta, and Ta is a direct base type of Tb. A type Tb is an extension of a type Ta (Ta is a base type of Tb) if

1. Ta and Tb are the same types, or
2. Tb is a direct extension of an extension of Ta

If Pa`= POINTER TO` Ta and Pb`= POINTER TO` Tb, Pb is an extension of Pa (Pa is a base type of Pb) if Tb is an extension of Ta.

## Assignment compatible

An expression e of type Te is assignment compatible with a variable v of type Tv if one of the following conditions hold:

1. Te and Tv are the same type;
2. Te and Tv are numeric types and Tv includes Te;
3. Te and Tv are record types and Te is an extension of Tv and the dynamic type of v is Tv ;
4. Te and Tv are pointer types and Te is an extension of Tv;
5. Tv is a pointer or a procedure type and e is NIL;
6. Tv is ARRAY n OF CHAR, e is a string constant with m characters, and m < n;
7. Tv is a procedure type and e is the name of a procedure whose formal parameters match those of Tv.

## Array compatible

An actual parameter a of type Ta is array compatible with a formal parameter f of type Tf if

1. Tf and Ta are the same type, or
2. Tf is an open array, Ta is any array, and their element types are array compatible, or
3. Tf is ARRAY OF CHAR and a is a string.

## Expression compatible

For a given operator, the types of its operands are expression compatible if they conform to the following table (which shows also the result type of the expression). Character arrays to be compared must contain 0X as a terminator. Type T1 must be an extension of type T0:

operator | first operand | second operand | result type
`+ - *` | numeric | numeric | smallest numeric type including both operands
`/` | numeric | numeric | smallest real type including both operands
`+ - * /` | SET | SET | SET
DIV MOD | integer | integer | smallest integer type including both operands
OR `&` `~` | BOOLEAN | BOOLEAN | BOOLEAN
`= # < <= > >=` | numeric | numeric | BOOLEAN
| CHAR | CHAR | BOOLEAN
| character array, string | character array, string | BOOLEAN
`= #` | BOOLEAN | BOOLEAN | BOOLEAN
| SET | SET | BOOLEAN
| NIL, POINTER TO T0 or T1 | NIL, POINTER TO T0 or T1 | BOOLEAN
| procedure type T, NIL | procedure type T, NIL | BOOLEAN
IN | integer | SET | BOOLEAN
IS | pointer | pointer | BOOLEAN
| record | record | BOOLEAN

## Matching formal parameter lists

Two formal parameter lists match if

1. they have the same number of parameters, and
2. they have either the same function result type or none, and
3. parameters at corresponding positions have equal types, and
4. parameters at corresponding positions are both either value or variable parameters.