next up previous
Next: Subrange types Up: The Pascal type model Previous: Required simple types

Enumerated types

Enumerated types[9]:
CLASS enumType() BEGIN
  OPER
    enumOrd(enumType): intType;
    enumeq, enumne, enumls, enumgt, enumle,
      enumge(enumType,enumType): boolType;
END;

INDICATION
  ordType: enumOrd;
  equal: enumeq;
  lsgt: enumne;
  less: enumls;
  greater: enumle;
  lessequal: enumle;
  greaterequal: enumge;
This macro is invoked in definition 3.

Each enumerated type needs a set type, because set expressions can be used as subexpressions without the corresponding set type being declared. The reason for this canonical set type is that in a set expression made up of constants the constants are of the base type.

Establish a user-defined type[10]:
ATTR CanonicalSet: DefTableKey;

RULE: TypeDenoter ::=  '(' Enumerate ')' COMPUTE
  .CanonicalSet=NewType();
  TypeDenoter.GotType=
    ORDER(
      AddTypeToBlock(
        .CanonicalSet,
        SetTypes,
        SingleDefTableKeyList(TypeDenoter.Type)),
      ResetCanonicalSet(TypeDenoter.Type,.CanonicalSet));
  TypeDenoter.GotOper=
    ORDER(
      InstClass0(enumType,TypeDenoter.Type),
      InstClass1(setType,.CanonicalSet,TypeDenoter.Type),
      MonadicOperator(
        makeset,
        NoOprName,
        TypeDenoter.Type,
        FinalType(.CanonicalSet)));
  Enumerate.Type=TypeDenoter.Type;
END;
This macro is defined in definitions 4, 10, 13, 15, 16, 18, 21, and 23.
This macro is invoked in definition 1.

Property definitions[11]:
CanonicalSet: DefTableKey;
makeset;
This macro is defined in definitions 11, 19, 24, 30, 34, and 38.
This macro is invoked in definition 7.


next up previous
Next: Subrange types Up: The Pascal type model Previous: Required simple types
2008-08-29