Oil Reference Manual
OIL deals with three primary concepts: operators, types and indications. The operators which OIL refers to are strongly typed functions. The types which are named in an OIL specification are referred to as `primitive types' but there are also `constructed types' which are created at compile time. Indications are a name given to a list of operators which may be identified by an appearance of an indication in an expression.
Although operators, types and indications are primary terms in discussing OIL and operator identification, the rest of this chapter is devoted to explanations of:
Anyone familiar with compiler construction is familiar with operator identification but may not necessarily know it by that name. Thus operator identification is introduced by an example.
In Pascal the
The operation of `matching' the operand type with the type signature is really the relation `is coercible to', see Coercions.
A coercion is a distinguished operator which the compiler may insert in
an expression to make operator identification possible. In the previous
section the Pascal expression
If there is a coercion from type A to type B then type A is said to be `coercible to' type B.
A coercion sequence is any number of coercions applied in sequence. In OIL a coercion sequence is used as if it were a single coercion. Thus if type A is coercible to type B and type B is coercible to type C then there is a coercion sequence from type A to type C. The elements in the sequence are the coercion operators in the order they need to be applied to satisfy the type constraint. Thus using a coercion sequence type A may match and argument of type C.
Coercion sequences lead to a revised definition of `coercible to'. If there is a coercion sequence from type A to type B then type A is said to be `coercible to' type B. Note that since a coercion sequence may be empty every type is coercible to itself.
Each type has an associated set of possible types. A type B is in the set of possible types for type A if A is coercible to B.
Likewise an expression may have a set of possible types. Take
Note that the set of possible types is a transitive closure of the relation `is coercible to'. When a new coercion is created then the transitive closure of every type may need to be updated. But in practice this is not the case and most coercions have no impact on the set of possible types for most types.
Formally OIL's classes are parametric abstract types. But they may be most easily comprehended as a procedure which takes some types as an argument and creates a new type and adds a set of operators and coercions into an existing type schema. The net effect being that the new operators may now be identified and the set of possible types for some types may be increased.
Consider the subrange type constructor in Pascal. It creates a coercion from the subrange to the base type.
You will want associate semantics to the identifiers in your OIL specification. Names allow a convenient way of doing that. All types, classes and operators have names associated with them. The name is represented as a definition table key (see The Definition Table Module of Definition Table) and can be referenced in your attribute grammar by the identifier used in the OIL specification.
The name associated with an ADT type, class or operator is accessed by
using the unary functions: