Next: , Previous: Conversion, Up: Top


7 User-Defined Types

A language that permits user-defined types must provide constructs for the user to specify the properties of such types. If user-defined types can be named, then defining and applied occurrences of type identifiers must be recognized and checked for correct usage.

Here are some examples of user-defined types in Mystery:

     TYPE Inches = INTEGER;
     TYPE Length = Row;
     TYPE Matrix = ARRAY [1 TO 10] OF Row;
     TYPE Row    = ARRAY [1 TO 10] OF Inches;
     TYPE Column = ARRAY [1 TO 10] OF Inches;
     TYPE Math   = PROCEDURE (i: Inches, r: Row): Column;

This sequence of type declarations defines six type identifiers (Inches, Length, Matrix, Row, Column, and Math). The second declaration states clearly that the identifiers Length and Row name the same type, but the identifiers Row and Column may or may not name the same type (see Type equivalence). Finally, the type [1 TO 10] is anonymous; it is not named by any type identifier.

Computational roles to support user-defined types are provided by the Typing module (see Typed Entities):

TypeDenotation
The computational role inherited by a grammar symbol that represents a subtree denoting a type. Its Type attribute is a new, unique, definition table key.
TypeDefDefId
ChkTypeDefDefId
The computational roles inherited by a grammar symbol that represents a defining occurrence of a type identifier.
TypeDefUseId
ChkTypeDefUseId
The computational roles inherited by a grammar symbol that represents an applied occurrence of a type identifier.