DocAda(tm) is a productivity tool of KSCE
|
|
|
|
About DocAda Light:
Preface / Preliminary
/ Help
/ TOC
/ Copyright
DocAda Online at the Ada Home:
Complete RM95
/ Updates
/ News
An enumeration_type_definition defines an enumeration type.
Syntax
enumeration_type_definition ::= (enumeration_literal_specification {, enumeration_literal_specification}) enumeration_literal_specification ::= defining_identifier | defining_character_literal defining_character_literal ::= character_literal
Legality Rules
The defining_identifiers and defining_character_literals listed in an enumeration_type_definition shall be distinct.
Static Semantics
Each enumeration_literal_specification is the explicit declaration of the corresponding enumeration literal: it declares a parameterless function, whose defining name is the defining_identifier or defining_character_literal, and whose result type is the enumeration type.
Each enumeration literal corresponds to a distinct value of the enumeration type, and to a distinct position number. The position number of the value of the first listed enumeration literal is zero; the position number of the value of each subsequent enumeration literal is one more than that of its predecessor in the list.
The predefined order relations between values of the enumeration type follow the order of corresponding position numbers.
If the same defining_identifier or defining_character_literal is specified in more than one enumeration_type_definition, the corresponding enumeration literals are said to be overloaded. At any place where an overloaded enumeration literal occurs in the text of a program, the type of the enumeration literal has to be determinable from the context (see 8.6).
Dynamic Semantics
The elaboration of an enumeration_type_definition creates the enumeration type and its first subtype, which is constrained to the base range of the type.
When called, the parameterless function associated with an enumeration literal returns the corresponding value of the enumeration type.
Examples
Examples of enumeration types and subtypes:
type Day is (Mon, Tue, Wed, Thu, Fri, Sat, Sun); type Suit is (Clubs, Diamonds, Hearts, Spades); type Gender is (M, F); type Level is (Low, Medium, Urgent); type Color is (White, Red, Yellow, Green, Blue, Brown, Black); type Light is (Red, Amber, Green); -- Red and Green are overloaded type Hexa is ('A', 'B', 'C', 'D', 'E', 'F'); type Mixed is ('A', 'B', '*', B, None, '?', '%'); subtype Weekday is Day range Mon .. Fri; subtype Major is Suit range Hearts .. Spades; subtype Rainbow is Color range Red .. Blue; -- the Color Red, not the Light
About DocAda Light:
Preface / Preliminary
/ Help
/ TOC
/ Copyright
DocAda Online at the Ada Home:
Complete RM95
/ Updates
/ News
|
|
|
|