basic_declaration ::= type_declaration | subtype_declaration | object_declaration | number_declaration | subprogram_declaration | abstract_subprogram_declaration | package_declaration | renaming_declaration | exception_declaration | generic_declaration | generic_instantiation
defining_identifier ::= identifierStatic Semantics
Static Semantics
all types elementary scalar discrete enumeration character boolean other enumeration integer signed integer modular integer real floating point fixed point ordinary fixed point decimal fixed point access access-to-object access-to-subprogram composite array string other array untagged record tagged task protected
type_declaration ::= full_type_declaration | incomplete_type_declaration | private_type_declaration | private_extension_declaration
full_type_declaration ::= type defining_identifier [known_discriminant_part] is type_definition; | task_type_declaration | protected_type_declaration
type_definition ::= enumeration_type_definition | integer_type_definition | real_type_definition | array_type_definition | record_type_definition | access_type_definition | derived_type_definitionLegality Rules
(White, Red, Yellow, Green, Blue, Brown, Black) range 1 .. 72 array(1 .. 10) of Integer
type Color is (White, Red, Yellow, Green, Blue, Brown, Black); type Column is range 1 .. 72; type Table is array(1 .. 10) of Integer;NOTES
subtype_declaration ::= subtype defining_identifier is subtype_indication;
subtype_indication ::= subtype_mark [constraint]
subtype_mark ::= subtype_name
constraint ::= scalar_constraint | composite_constraint
scalar_constraint ::= range_constraint | digits_constraint | delta_constraint
composite_constraint ::= index_constraint | discriminant_constraintName Resolution Rules
subtype Rainbow is Color range Red .. Blue; -- see section Type Declarations subtype Red_Blue is Rainbow; subtype Int is Integer; subtype Small_Int is Integer range -10 .. 10; subtype Up_To_K is Column range 1 .. K; -- see section Type Declarations subtype Square is Matrix(1 .. 10, 1 .. 10); -- see section Array Types subtype Male is Person(Sex => M); -- see section Incomplete Type Declarations
Static Semantics
object_declaration ::= defining_identifier_list : [aliased] [constant] subtype_indication [:= expression]; | defining_identifier_list : [aliased] [constant] array_type_definition [:= expression]; | single_task_declaration | single_protected_declaration
defining_identifier_list ::= defining_identifier {, defining_identifier}Name Resolution Rules
-- the multiple object declaration
John, Paul : Person_Name := new Person(Sex => M); -- see section Incomplete Type Declarations
-- is equivalent to the two single object -- declarations in the order given
John : Person_Name := new Person(Sex => M); Paul : Person_Name := new Person(Sex => M);
Count, Sum : Integer; Size : Integer range 0 .. 10_000 := 0; Sorted : Boolean := False; Color_Table : array(1 .. Max) of Color; Option : Bit_Vector(1 .. 10) := (others => True); Hello : constant String := "Hi, world.";
Limit : constant Integer := 10_000; Low_Limit : constant Integer := Limit/10; Tolerance : constant Real := Dispersion(1.15);
number_declaration ::= defining_identifier_list : constant := static_expression;Name Resolution Rules
Two_Pi : constant := 2.0*Ada.Numerics.Pi; -- a real number, see section The Numerics Packages
Max : constant := 500; -- an integer number Max_Line_Size : constant := Max/6; -- the integer 83 Power_16 : constant := 2**16; -- the integer 65_536 One, Un, Eins : constant := 1; -- three different names for 1
derived_type_definition ::= [abstract] new parent_subtype_indication [record_extension_part]Legality Rules
type Local_Coordinate is new Coordinate; -- two different types type Midweek is new Day range Tue .. Thu; -- see section Enumeration Types type Counter is new Positive; -- same range as Positive
type Special_Key is new Key_Manager.Key; -- see section Private Operations -- the inherited subprograms have the following specifications: -- procedure Get_Key(K : out Special_Key); -- function "<"(X,Y : Special_Key) return Boolean;
1 + 4 < 7
range_constraint ::= range range
range ::= range_attribute_reference | simple_expression .. simple_expression
S'First denotes the lower bound of the range of S. The value of this attribute is of the type of S.
S'Last denotes the upper bound of the range of S. The value of this attribute is of the type of S.
S'Range is equivalent to the range S'First .. S'Last.
S'Base denotes an unconstrained subtype of the type of S. This unconstrained subtype is called the base subtype of the type.
function S'Min(Left, Right : S'Base) return S'Base
function S'Max(Left, Right : S'Base) return S'Base
function S'Succ(Arg : S'Base) return S'Base
function S'Pred(Arg : S'Base) return S'Base
function S'Wide_Image(Arg : S'Base) return Wide_String
function S'Image(Arg : S'Base) return String
S'Wide_Width denotes the maximum length of a Wide_String returned by S'Wide_Image over all values of the subtype S. It denotes zero for a subtype that has a null range. Its type is universal_integer.
S'Width denotes the maximum length of a String returned by S'Image over all values of the subtype S. It denotes zero for a subtype that has a null range. Its type is universal_integer.
function S'Wide_Value(Arg : Wide_String) return S'Base
function S'Value(Arg : String) return S'Base
Implementation Permissions
-10 .. 10 X .. X + 1 0.0 .. 2.0*Pi Red .. Green -- see section Enumeration Types 1 .. 0 -- a null range Table'Range -- a range attribute reference, see section Array Types
range -999.0 .. +999.0 range S'First+1 .. S'Last-1
enumeration_type_definition ::= (enumeration_literal_specification {, enumeration_literal_specification})
enumeration_literal_specification ::= defining_identifier | defining_character_literal
defining_character_literal ::= character_literalLegality Rules
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
Static Semantics
type Roman_Digit is ('I', 'V', 'X', 'L', 'C', 'D', 'M');
Static Semantics
integer_type_definition ::= signed_integer_type_definition | modular_type_definition
signed_integer_type_definition ::= range static_simple_expression .. static_simple_expression
modular_type_definition ::= mod static_expressionName Resolution Rules
subtype Natural is Integer range 0 .. Integer'Last; subtype Positive is Integer range 1 .. Integer'Last;
S'Modulus yields the modulus of the type of S, as a value of the type universal_integer.Dynamic Semantics
type Page_Num is range 1 .. 2_000; type Line_Size is range 1 .. Max_Line_Size;
subtype Small_Int is Integer range -10 .. 10; subtype Column_Ptr is Line_Size range 1 .. 10; subtype Buffer_Size is Integer range 0 .. Max;
type Byte is mod 256; -- an unsigned byte type Hash_Index is mod 97; -- modulus is prime
Static Semantics
function S'Pos(Arg : S'Base) return universal_integer
function S'Val(Arg : universal_integer) return S'Base
Implementation Advice
S'Val(S'Pos(X)) = X S'Pos(S'Val(N)) = NExamples
-- For the types and subtypes declared in subclause -- see section Enumeration Types, the following hold:
-- Color'First = White, Color'Last = Black -- Rainbow'First = Red, Rainbow'Last = Blue
-- Color'Succ(Blue) = Rainbow'Succ(Blue) = Brown -- Color'Pos(Blue) = Rainbow'Pos(Blue) = 4 -- Color'Val(0) = Rainbow'Val(0) = White
real_type_definition ::= floating_point_definition | fixed_point_definitionStatic Semantics
floating_point_definition ::= digits static_expression [real_range_specification]
real_range_specification ::= range static_simple_expression .. static_simple_expressionName Resolution Rules
type Coefficient is digits 10 range -1.0 .. 1.0;
type Real is digits 8; type Mass is digits 7 range 0.0 .. 1.0E35;
subtype Probability is Real range 0.0 .. 1.0; -- a subtype with a smaller range
Static Semantics
S'Digits denotes the requested decimal precision for the subtype S. The value of this attribute is of the type universal_integer. The requested decimal precision of the base subtype of a floating point type T is defined to be the largest value of d for which ceiling(d * log(10) / log(T'Machine_Radix)) + 1 <= T'Model_Mantissa.NOTES
fixed_point_definition ::= ordinary_fixed_point_definition | decimal_fixed_point_definition
ordinary_fixed_point_definition ::= delta static_expression real_range_specification
decimal_fixed_point_definition ::= delta static_expression digits static_expression [real_range_specification]
digits_constraint ::= digits static_expression [range_constraint]Name Resolution Rules
type Fraction is delta 2.0**(-15) range -1.0 .. 1.0;
type Volt is delta 0.125 range 0.0 .. 255.0;
-- A pure fraction which requires all the available -- space in a word can be declared as the type Fraction: type Fraction is delta System.Fine_Delta range -1.0 .. 1.0; -- Fraction'Last = 1.0 - System.Fine_Delta
type Money is delta 0.01 digits 15; -- decimal fixed point subtype Salary is Money digits 10; -- Money'Last = 10.0**13 - 0.01, Salary'Last = 10.0**8 - 0.01
Static Semantics
S'Small denotes the small of the type of S. The value of this attribute is of the type universal_real. Small may be specified for nonderived fixed point types via an attribute_definition_clause, see section Representation Attributes; the expression of such a clause shall be static.
S'Delta denotes the delta of the fixed point subtype S. The value of this attribute is of the type universal_real.
S'Fore yields the minimum number of characters needed before the decimal point for the decimal representation of any value of the subtype S, assuming that the representation does not include an exponent, but includes a one-character prefix that is either a minus sign or a space. (This minimum number does not include superfluous zeros or underlines, and is at least 2.) The value of this attribute is of the type universal_integer.
S'Aft yields the number of decimal digits needed after the decimal point to accommodate the delta of the subtype S, unless the delta of the subtype S is greater than 0.1, in which case the attribute yields the value one. (S'Aft is the smallest positive integer N for which (10**N)*S'Delta is greater than or equal to one.) The value of this attribute is of the type universal_integer.
S'Digits denotes the digits of the decimal fixed point subtype S, which corresponds to the number of decimal digits that are representable in objects of the subtype. The value of this attribute is of the type universal_integer. Its value is determined as follows:
S'Scale denotes the scale of the subtype S, defined as the value N such that S'Delta = 10.0**(-N). The scale indicates the position of the point relative to the rightmost significant digits of values of subtype S. The value of this attribute is of the type universal_integer.
function S'Round(X : universal_real) return S'Base
array_type_definition ::= unconstrained_array_definition | constrained_array_definition
unconstrained_array_definition ::= array(index_subtype_definition {, index_subtype_definition}) of component_definition
index_subtype_definition ::= subtype_mark range <>
constrained_array_definition ::= array (discrete_subtype_definition {, discrete_subtype_definition}) of component_definition
discrete_subtype_definition ::= discrete_subtype_indication | range
component_definition ::= [aliased] subtype_indicationName Resolution Rules
type Vector is array(Integer range <>) of Real; type Matrix is array(Integer range <>, Integer range <>) of Real; type Bit_Vector is array(Integer range <>) of Boolean; type Roman is array(Positive range <>) of Roman_Digit; -- see section Character Types
type Table is array(1 .. 10) of Integer; type Schedule is array(Day) of Boolean; type Line is array(1 .. Max_Line_Size) of Character;
Grid : array(1 .. 80, 1 .. 100) of Boolean; Mix : array(Color range Red .. Green) of Boolean; Page : array(Positive range <>) of Line := -- an array of arrays (1 | 50 => Line'(1 | Line'Last => '+', others => '-'), -- see section Array Aggregates 2 .. 49 => Line'(1 | Line'Last => '|', others => ' ')); -- Page is constrained by its initial value to (1..50)
index_constraint ::= (discrete_range {, discrete_range})
discrete_range ::= discrete_subtype_indication | rangeName Resolution Rules
Board : Matrix(1 .. 8, 1 .. 8); -- see section Array Types Rectangle : Matrix(1 .. 20, 1 .. 30); Inverse : Matrix(1 .. N, 1 .. N); -- N need not be static
Filter : Bit_Vector(0 .. 31);
My_Schedule : Schedule; -- all arrays of type Schedule have the same bounds
type Var_Line(Length : Natural) is record Image : String(1 .. Length); end record;
Null_Line : Var_Line(0); -- Null_Line.Image is a null array
Legality Rules
A'First denotes the lower bound of the first index range; its type is the corresponding index type.
A'First(N) denotes the lower bound of the N-th index range; its type is the corresponding index type.
A'Last denotes the upper bound of the first index range; its type is the corresponding index type.
A'Last(N) denotes the upper bound of the N-th index range; its type is the corresponding index type.
A'Range is equivalent to the range A'First .. A'Last, except that the prefix A is only evaluated once.
A'Range(N) is equivalent to the range A'First(N) .. A'Last(N), except that the prefix A is only evaluated once.
A'Length denotes the number of values of the first index range (zero for a null range); its type is universal_integer.
A'Length(N) denotes the number of values of the N-th index range (zero for a null range); its type is universal_integer.Implementation Advice
A'Length(N) = A'Last(N) - A'First(N) + 1
-- Filter'First = 0 -- Filter'Last = 31 -- Filter'Length = 32 -- Rectangle'Last(1) = 20 -- Rectangle'Last(2) = 30
Static Semantics
subtype Positive is Integer range 1 .. Integer'Last;
type String is array(Positive range <>) of Character; type Wide_String is array(Positive range <>) of Wide_Character;NOTES
Stars : String(1 .. 120) := (1 .. 120 => '*' ); Question : constant String := "How many characters?"; -- Question'First = 1, Question'Last = 20 -- Question'Length = 20 (the number of characters)
Ask_Twice : String := Question & Question; -- constrained to (1..40) Ninety_Six : constant Roman := "XCVI"; -- see section Character Types, and section Array Types
discriminant_part ::= unknown_discriminant_part | known_discriminant_part
unknown_discriminant_part ::= (<>)
known_discriminant_part ::= (discriminant_specification {; discriminant_specification})
discriminant_specification ::= defining_identifier_list : subtype_mark [:= default_expression] | defining_identifier_list : access_definition [:= default_expression]
default_expression ::= expressionName Resolution Rules
type Buffer(Size : Buffer_Size := 100) is -- see section Integer Types record Pos : Buffer_Size := 0; Value : String(1 .. Size); end record;
type Matrix_Rec(Rows, Columns : Integer) is record Mat : Matrix(1 .. Rows, 1 .. Columns); -- see section Array Types end record;
type Square(Side : Integer) is new Matrix_Rec(Rows => Side, Columns => Side);
type Double_Square(Number : Integer) is record Left : Square(Number); Right : Square(Number); end record;
type Item(Number : Positive) is record Content : Integer; -- no component depends on the discriminant end record;
discriminant_constraint ::= (discriminant_association {, discriminant_association})
discriminant_association ::= [discriminant_selector_name {| discriminant_selector_name} =>] expression
Name Resolution Rules
Large : Buffer(200); -- constrained, always 200 characters -- (explicit discriminant value) Message : Buffer; -- unconstrained, initially 100 characters -- (default discriminant value) Basis : Square(5); -- constrained, always 5 by 5 Illegal : Square; -- illegal, a Square has to be constrained
Yields the value True if A denotes a constant, a value, or a constrained variable, and False otherwise.Erroneous Execution
record_type_definition ::= [[abstract] tagged] [limited] record_definition
record_definition ::= record component_list end record | null record
component_list ::= component_item {component_item} | {component_item} variant_part | null;
component_item ::= component_declaration | representation_clause
component_declaration ::= defining_identifier_list : component_definition [:= default_expression];Name Resolution Rules
type Date is record Day : Integer range 1 .. 31; Month : Month_Name; Year : Integer range 0 .. 4000; end record;
type Complex is record Re : Real := 0.0; Im : Real := 0.0; end record;
Tomorrow, Yesterday : Date; A, B, C : Complex;
-- both components of A, B, and C are implicitly initialized to zero
variant_part ::= case discriminant_direct_name is variant {variant} end case;
variant ::= when discrete_choice_list => component_list
discrete_choice_list ::= discrete_choice {| discrete_choice}
discrete_choice ::= expression | discrete_range | othersName Resolution Rules
type Device is (Printer, Disk, Drum); type State is (Open, Closed);
type Peripheral(Unit : Device := Disk) is record Status : State; case Unit is when Printer => Line_Count : Integer range 1 .. Page_Size; when others => Cylinder : Cylinder_Index; Track : Track_Number; end case; end record;
subtype Drum_Unit is Peripheral(Drum); subtype Disk_Unit is Peripheral(Disk);
Writer : Peripheral(Unit => Printer); Archive : Disk_Unit;
package Ada.Tags is type Tag is private;
function Expanded_Name(T : Tag) return String; function External_Tag(T : Tag) return String; function Internal_Tag(External : String) return Tag;
Tag_Error : exception;
private ... -- not specified by the language end Ada.Tags;
S'Class denotes a subtype of the class-wide type (called T'Class in this International Standard) for the class rooted at T (or if S already denotes a class-wide subtype, then S'Class is the same as S).
S'Tag denotes the tag of the type T (or if T is class-wide, the tag of the root type of the corresponding class). The value of this attribute is of type Tag.
X'Tag denotes the tag of X. The value of this attribute is of type Tag.Dynamic Semantics
type Point is tagged record X, Y : Real := 0.0; end record;
type Expression is tagged null record; -- Components will be added by each extension
record_extension_part ::= with record_definitionLegality Rules
type Painted_Point is new Point with record Paint : Color := White; end record; -- Components X and Y are inherited
Origin : constant Painted_Point := (X | Y => 0.0, Paint => Black);
type Literal is new Expression with record -- a leaf in an Expression tree Value : Real; end record;
type Expr_Ptr is access all Expression'Class; -- see section Access Types
type Binary_Operation is new Expression with record -- an internal node in an Expression tree Left, Right : Expr_Ptr; end record;
type Addition is new Binary_Operation with null record; type Subtraction is new Binary_Operation with null record; -- No additional components needed for these extensions
Tree : Expr_Ptr := -- A tree representation of ``5.0 + (13.0-7.0)'' new Addition'( Left => new Literal'(Value => 5.0), Right => new Subtraction'( Left => new Literal'(Value => 13.0), Right => new Literal'(Value => 7.0)));
package Sets is subtype Element_Type is Natural; type Set is abstract tagged null record; function Empty return Set is abstract; function Union(Left, Right : Set) return Set is abstract; function Intersection(Left, Right : Set) return Set is abstract; function Unit_Set(Element : Element_Type) return Set is abstract; procedure Take (Element : out Element_Type; From : in out Set) is abstract; end Sets;NOTES
access_type_definition ::= access_to_object_definition | access_to_subprogram_definition
access_to_object_definition ::= access [general_access_modifier] subtype_indication
general_access_modifier ::= all | constant
access_to_subprogram_definition ::= access [protected] procedure parameter_profile | access [protected] function parameter_and_result_profile
access_definition ::= access subtype_markStatic Semantics
type Peripheral_Ref is access Peripheral; -- see section Variant Parts and Discrete Choices type Binop_Ptr is access all Binary_Operation'Class; -- general access-to-class-wide, see section Type Extensions
subtype Drum_Ref is Peripheral_Ref(Drum); -- see section Variant Parts and Discrete Choices
type Message_Procedure is access procedure (M : in String := "Error!"); procedure Default_Message_Procedure(M : in String); Give_Message : Message_Procedure := Default_Message_Procedure'Access; ... procedure Other_Procedure(M : in String); ... Give_Message := Other_Procedure'Access; ... Give_Message("File not found."); -- call with parameter (.all is optional) Give_Message.all; -- call with no parameters
incomplete_type_declaration ::= type defining_identifier [discriminant_part];Legality Rules
type Cell; -- incomplete type declaration type Link is access Cell;
type Cell is record Value : Integer; Succ : Link; Pred : Link; end record;
Head : Link := new Cell'(0, null, null); Next : Link := Head.Succ;
type Person(<>); -- incomplete type declaration type Car; -- incomplete type declaration
type Person_Name is access Person; type Car_Name is access all Car;
type Car is record Number : Integer; Owner : Person_Name; end record;
type Person(Sex : Gender) is record Name : String(1 .. 20); Birth : Date; Age : Integer range 0 .. 130; Vehicle : Car_Name; case Sex is when M => Wife : Person_Name(Sex => F); when F => Husband : Person_Name(Sex => M); end case; end record;
My_Car, Your_Car, Next_Car : Car_Name := new Car; -- see section Allocators George : Person_Name := new Person(M); ... George.Vehicle := Your_Car;
X'Access yields an access value that designates the object denoted by X. The type of X'Access is an access-to-object type, as determined by the expected type. The expected type shall be a general access type. X shall denote an aliased view of an object, including possibly the current instance, See section The Context of Overload Resolution, of a limited type within its definition, or a formal parameter or generic formal object of a tagged type. The view denoted by the prefix X shall satisfy the following additional requirements, presuming the expected type for X'Access is the general access type A:
P'Access yields an access value that designates the subprogram denoted by P. The type of P'Access is an access-to-subprogram type (S), as determined by the expected type. The accessibility level of P shall not be statically deeper than that of S. In addition to the places where Legality Rules normally apply, see section Generic Instantiation, this rule applies also in the private part of an instance of a generic unit. The profile of P shall be subtype-conformant with the designated profile of S, and shall not be Intrinsic. If the subprogram denoted by P is declared within a generic body, S shall be declared within the generic body.NOTES
Martha : Person_Name := new Person(F); -- see section Incomplete Type Declarations Cars : array (1..2) of aliased Car; ... Martha.Vehicle := Cars(1)'Access; George.Vehicle := Cars(2)'Access;
declarative_part ::= {declarative_item}
declarative_item ::= basic_declarative_item | body
basic_declarative_item ::= basic_declaration | representation_clause | use_clause
body ::= proper_body | body_stub
proper_body ::= subprogram_body | package_body | task_body | protected_bodyDynamic Semantics
Legality Rules
Go to the first, previous, next, last section, table of contents.