!topic Title summarizing comment !reference RM95-ss.ss(pp) !from Author Name yy-mm-dd !keywords keywords related to topic !discussion text of discussion
!topic [c]{C}haracter
!topic it[']s meaning is not defined
Syntax
Name Resolution Rules
Legality Rules
Static Semantics
Post-Compilation Rules
Dynamic Semantics
Bounded (Run-Time) Errors
Erroneous Execution
Implementation Requirements
Documentation Requirements
Metrics
Implementation Permissions
Implementation Advice
Examples
Implementation Requirements
Documentation Requirements
Implementation Advice
case_statement
array
return_statement ::= return [expression]; return_statement ::= return; | return expression;
term ::= factor {multiplying_operator factor}
term ::= factor | term multiplying_operator factor
constraint ::= scalar_constraint | composite_constraint
discrete_choice_list ::= discrete_choice {| discrete_choice}
if_statement ::=
if condition then
sequence_of_statements
{elsif condition then
sequence_of_statements}
[else
sequence_of_statements]
end if;
Implementation Requirements
Implementation Permissions
Implementation Advice
Syntax
character ::=
graphic_character
| format_effector
| other_control_function
graphic_character ::=
identifier_letter
| digit
| space_character
| special_character
Static Semantics
upper_case_identifier_letter | lower_case_identifier_letter
Any character of Row 00 of ISO 10646 BMP whose name begins "Latin Capital Letter".
Any character of Row 00 of ISO 10646 BMP whose name begins "Latin Small Letter".
One of the characters 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9.
The character of ISO 10646 BMP named "Space".
Any character of the ISO 10646 BMP that is not reserved for a control function, and is not the space_character, an identifier_letter, or a digit.
The control functions of ISO 6429 called character tabulation (HT), line tabulation (VT), carriage return (CR), line feed (LF), and form feed (FF).
Any control function, other than a format_effector, that is allowed in a comment; the set of other_control_functions allowed in comments is implementation defined.
symbol name symbol name
" quotation mark : colon
# number sign ; semicolon
& ampersand < less-than sign
' apostrophe, tick = equals sign
( left parenthesis > greater-than sign
) right parenthesis _ low line, underline
* asterisk, multiply | vertical line
+ plus sign [ left square bracket
, comma ] right square bracket
- hyphen-minus, minus { left curly bracket
. full stop, dot, point } right curly bracket
/ solidus, divide
Implementation Permissions
Static Semantics
& ' ( ) * + , - . / : ; < = > |
=> .. ** := /= >= <= << >> <>
delimiter name => arrow .. double dot ** double star, exponentiate := assignment (pronounced: "becomes") /= inequality (pronounced: "not equal") >= greater than or equal <= less than or equal << left label bracket >> right label bracket <> box
Implementation Requirements
Syntax
identifier ::= identifier_letter {[underline] letter_or_digit}
letter_or_digit ::= identifier_letter | digit
Static Semantics
Implementation Permissions
Examples
Count X Get_Symbol Ethelyn Marion Snobol_4 X1 Page_Count Store_Next_Item
Syntax
numeric_literal ::= decimal_literal | based_literalNOTES
Syntax
decimal_literal ::= numeral [.numeral] [exponent]
numeral ::= digit {[underline] digit}
exponent ::= E [+] numeral | E - numeral
Static Semantics
Examples
12 0 1E6 123_456 -- integer literals 12.0 0.0 0.456 3.14159_26 -- real literals
Syntax
based_literal ::= base # based_numeral [.based_numeral] # [exponent]
base ::= numeral
based_numeral ::=
extended_digit {[underline] extended_digit}
extended_digit ::= digit | A | B | C | D | E | F
Legality Rules
Static Semantics
Examples
2#1111_1111# 16#FF# 016#0ff# -- integer literals of value 255 16#E#E1 2#1110_0000# -- integer literals of value 224 16#F.FF#E+2 2#1.1111_1111_1110#E11 -- real literals of value 4095.0
Syntax
character_literal ::= 'graphic_character'NOTES
Examples
'A' '*' "' ' '
Syntax
string_literal ::= "{string_element}"
string_element ::= "" | non_quotation_mark_graphic_character
Static Semantics
Examples
"Message of the day:" "" -- a null string literal " " "A" """" -- three string literals of length 1 "Characters such as $, %, and } are allowed in string literals"
Syntax
comment ::= --{non_end_of_line_character}
Static Semantics
Examples
-- the last sentence above echoes the Algol 68 report end; -- processing of Line is complete -- a long comment may be split onto -- two or more consecutive lines ---------------- the first two hyphens start the comment
Syntax
pragma ::=
pragma identifier [(pragma_argument_association
{, pragma_argument_association})];
pragma_argument_association ::=
[pragma_argument_identifier =>] name
| [pragma_argument_identifier =>] expression
Static Semantics
Dynamic Semantics
Implementation Requirements
Implementation Permissions
Implementation Advice
Syntax
Static Semantics
Examples
pragma List(Off); -- turn off listing generation pragma Optimize(Off); -- turn off optional optimizations pragma Inline(Set_Mask); -- generate code for Set_Mask inline pragma Suppress(Range_Check, On => Index); -- turn off range checking on Index
Syntax
abort else new return
abs elsif not reverse
abstract end null
accept entry select
access exception separate
aliased exit of subtype
all or
and for others tagged
array function out task
at terminate
generic package then
begin goto pragma type
body private
if procedure
case in protected until
constant is use
raise
declare range when
delay limited record while
delta loop rem with
digits renames
do mod requeue xor
Syntax
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 ::= identifier
Static Semantics
Dynamic 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
Syntax
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_definition
Legality Rules
Static Semantics
Dynamic Semantics
Examples
(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
Syntax
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_constraint
Name Resolution Rules
Dynamic Semantics
Examples
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
Static Semantics
Syntax
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
Legality Rules
Static Semantics
Dynamic Semantics
Examples
-- 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);
Syntax
number_declaration ::= defining_identifier_list : constant := static_expression;
Name Resolution Rules
Legality Rules
Static Semantics
Dynamic Semantics
Examples
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
Syntax
derived_type_definition ::= [abstract] new parent_subtype_indication [record_extension_part]
Legality Rules
Static Semantics
Dynamic Semantics
Examples
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;
Static Semantics
1 + 4 < 7
Syntax
range_constraint ::= range range
range ::=
range_attribute_reference
| simple_expression .. simple_expression
Name Resolution Rules
Static Semantics
Dynamic Semantics
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
Examples
-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
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
Static Semantics
Dynamic Semantics
Examples
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
Implementation Permissions
Implementation Advice
Examples
type Roman_Digit is ('I', 'V', 'X', 'L', 'C', 'D', 'M');
Static Semantics
Syntax
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_expression
Name Resolution Rules
Legality Rules
Static Semantics
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
Implementation Requirements
Implementation Permissions
Implementation Advice
Examples
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)) = N
Examples
-- 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
Syntax
real_type_definition ::= floating_point_definition | fixed_point_definition
Static Semantics
Dynamic Semantics
Implementation Requirements
Implementation Permissions
Syntax
floating_point_definition ::= digits static_expression [real_range_specification]
real_range_specification ::= range static_simple_expression .. static_simple_expression
Name Resolution Rules
Legality Rules
Static Semantics
Dynamic Semantics
Implementation Requirements
Implementation Permissions
Implementation Advice
Examples
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
Syntax
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
Legality Rules
Static Semantics
Dynamic Semantics
Implementation Requirements
Implementation Permissions
type Fraction is delta 2.0**(-15) range -1.0 .. 1.0;
Examples
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
Syntax
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_indication
Name Resolution Rules
Legality Rules
Static Semantics
Dynamic Semantics
Examples
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)
Syntax
index_constraint ::= (discrete_range {, discrete_range})
discrete_range ::= discrete_subtype_indication | range
Name Resolution Rules
Legality Rules
Static Semantics
Dynamic Semantics
Examples
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
Static Semantics
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
Examples
-- 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
Examples
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
Syntax
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 ::= expression
Name Resolution Rules
Legality Rules
Static Semantics
Dynamic Semantics
Examples
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;
Syntax
discriminant_constraint ::=
(discriminant_association {, discriminant_association})
discriminant_association ::=
[discriminant_selector_name
{| discriminant_selector_name} =>] expression
Name Resolution Rules
Legality Rules
Dynamic Semantics
Examples
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
Static Semantics
Yields the value True if A denotes a constant, a value, or a constrained variable, and False otherwise.
Erroneous Execution
Syntax
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
Legality Rules
Static Semantics
Dynamic Semantics
Examples
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
Syntax
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 | others
Name Resolution Rules
Legality Rules
Static Semantics
Dynamic Semantics
Examples
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;
Static Semantics
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
Implementation Permissions
Examples
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
Syntax
record_extension_part ::= with record_definition
Legality Rules
Dynamic Semantics
Examples
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)));
Static Semantics
Legality Rules
Dynamic Semantics
Legality Rules
Examples
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
Syntax
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_mark
Static Semantics
Dynamic Semantics
Examples
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
Syntax
incomplete_type_declaration ::= type defining_identifier [discriminant_part];
Legality Rules
Static Semantics
Dynamic Semantics
Examples
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;
Name Resolution Rules
Static Semantics
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
Examples
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;
Syntax
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_body
Dynamic Semantics
Name Resolution Rules
Legality Rules
Syntax
name ::=
direct_name | explicit_dereference
| indexed_component | slice
| selected_component | attribute_reference
| type_conversion | function_call
| character_literal
direct_name ::= identifier | operator_symbol
prefix ::= name | implicit_dereference
explicit_dereference ::= name.all
implicit_dereference ::= name
Name Resolution Rules
Static Semantics
Dynamic Semantics
Examples
Pi -- the direct name of a number (see section Number Declarations) Limit -- the direct name of a constant (see section Object Declarations) Count -- the direct name of a scalar variable (see section Object Declarations) Board -- the direct name of an array variable (see section Index Constraints and Discrete Ranges) Matrix -- the direct name of a type (see section Array Types) Random -- the direct name of a function (see section Subprogram Declarations) Error -- the direct name of an exception (see section Exception Declarations)
Next_Car.all -- explicit dereference denoting the object
-- designated by the access variable Next_Car,
-- see section Incomplete Type Declarations
Next_Car.Owner -- selected component with implicit dereference;
-- same as Next_Car.all.Owner
Syntax
indexed_component ::= prefix(expression {, expression})
Name Resolution Rules
Static Semantics
Dynamic Semantics
Examples
My_Schedule(Sat) -- a component of a one-dimensional array (see see section Index Constraints and Discrete Ranges) Page(10) -- a component of a one-dimensional array (see see section Array Types) Board(M, J + 1) -- a component of a two-dimensional array (see see section Index Constraints and Discrete Ranges) Page(10)(20) -- a component of a component (see see section Array Types) Request(Medium) -- an entry in a family of entries (see see section Task Units and Task Objects) Next_Frame(L)(M, N) -- a component of a function call (see see section Subprogram Declarations)NOTES
Syntax
slice ::= prefix(discrete_range)
Name Resolution Rules
Static Semantics
Dynamic Semantics
Examples
Stars(1 .. 15) -- a slice of 15 characters (see section String Types) Page(10 .. 10 + Size) -- a slice of 1 + Size components (see section Array Types) Page(L)(A .. B) -- a slice of the array Page(L) (see section Array Types) Stars(1 .. 0) -- a null slice (see section String Types) My_Schedule(Weekday) -- bounds given by subtype (see section Index Constraints and Discrete Ranges, and section Enumeration Types) Stars(5 .. 15)(K) -- same as Stars(K) (see section String Types) -- provided that K is in 5 .. 15
Syntax
selected_component ::= prefix . selector_name
selector_name ::= identifier | character_literal | operator_symbol
Name Resolution Rules
Dynamic Semantics
Examples
Tomorrow.Month -- a record component (see section Record Types) Next_Car.Owner -- a record component (see section Incomplete Type Declarations) Next_Car.Owner.Age -- a record component (see section Incomplete Type Declarations) -- the previous two lines involve implicit dereferences Writer.Unit -- a record component (a discriminant) (see section Variant Parts and Discrete Choices) Min_Cell(H).Value -- a record component of the result (see section Subprogram Declarations) -- of the function call Min_Cell(H) Control.Seize -- an entry of a protected object (see section Protected Units and Protected Objects) Pool(K).Write -- an entry of the task Pool(K) (see section Protected Units and Protected Objects)
Key_Manager."<" -- an operator of the visible part of a package (see section Private Operations) Dot_Product.Sum -- a variable declared in a function body (see section Subprogram Declarations) Buffer.Pool -- a variable declared in a protected unit (see section Example of Tasking and Synchronization) Buffer.Read -- an entry of a protected unit (see section Example of Tasking and Synchronization) Swap.Temp -- a variable declared in a block statement (see section Block Statements) Standard.Boolean -- the name of a predefined type (see section The Package Standard)
Syntax
attribute_reference ::= prefix'attribute_designator
attribute_designator ::=
identifier[(static_expression)]
| Access | Delta | Digits
range_attribute_reference ::= prefix'range_attribute_designator
range_attribute_designator ::= Range[(static_expression)]
Name Resolution Rules
Legality Rules
Static Semantics
Dynamic Semantics
Implementation Permissions
Examples
Color'First -- minimum value of the enumeration type Color (see section Enumeration Types) Rainbow'Base'First -- same as Color'First (see section Enumeration Types) Real'Digits -- precision of the type Real (see section Floating Point Types) Board'Last(2) -- upper bound of the second dimension of Board (see section Index Constraints and Discrete Ranges) Board'Range(1) -- index range of the first dimension of Board (see section Index Constraints and Discrete Ranges) Pool(K)'Terminated -- True if task Pool(K) is terminated (see section Task Units and Task Objects) Date'Size -- number of bits for records of type Date (see section Record Types) Message'Address -- address of the record variable Message (see section Discriminant Constraints)
Name Resolution Rules
Legality Rules
Static Semantics
Dynamic Semantics
Examples
3.14159_26536 -- a real literal 1_345 -- an integer literal 'A' -- a character literal "Some Text" -- a string literal
Syntax
aggregate ::= record_aggregate | extension_aggregate | array_aggregate
Name Resolution Rules
Legality Rules
Dynamic Semantics
Syntax
record_aggregate ::= (record_component_association_list)
record_component_association_list ::=
record_component_association {, record_component_association}
| null record
record_component_association ::= [ component_choice_list => ] expression
component_choice_list ::=
component_selector_name {| component_selector_name}
| others
Name Resolution Rules
Legality Rules
Dynamic Semantics
Examples
(4, July, 1776) -- see section Record Types
(Day => 4, Month => July, Year => 1776) (Month => July, Day => 4, Year => 1776)
(Disk, Closed, Track => 5, Cylinder => 12) -- see section Variant Parts and Discrete Choices (Unit => Disk, Status => Closed, Cylinder => 9, Track => 1)
(Value => 0, Succ|Pred => new Cell'(0, null, null)) -- see section Incomplete Type Declarations
-- The allocator is evaluated twice: -- Succ and Pred designate different cells
Expression'(null record) Literal'(Value => 0.0) Painted_Point'(0.0, Pi/2.0, Paint => Red)
Syntax
extension_aggregate ::= (ancestor_part with record_component_association_list)
ancestor_part ::= expression | subtype_mark
Name Resolution Rules
Legality Rules
Static Semantics
Dynamic Semantics
Examples
Painted_Point'(Point with Red) (Point'(P) with Paint => Black)
(Expression with Left => 1.2, Right => 3.4) Addition'(Binop with null record) -- presuming Binop is of type Binary_Operation
Syntax
array_aggregate ::= positional_array_aggregate | named_array_aggregate
positional_array_aggregate ::=
(expression, expression {, expression})
| (expression {, expression}, others => expression)
named_array_aggregate ::=
(array_component_association {, array_component_association})
array_component_association ::= discrete_choice_list => expression
Name Resolution Rules
Legality Rules
Static Semantics
Dynamic Semantics
Examples
(7, 9, 5, 1, 3, 2, 4, 8, 6, 0) Table'(5, 8, 4, 1, others => 0) -- see section Array Types
(1 .. 5 => (1 .. 8 => 0.0)) -- two-dimensional (1 .. N => new Cell) -- N new cells, in particular for N = 0
Table'(2 | 4 | 10 => 1, others => 0) Schedule'(Mon .. Fri => True, others => False) Schedule'(Wed | Sun => False, others => True) -- see section Array Types Vector'(1 => 2.5) -- single-component vector
-- Three aggregates for the same value of subtype -- Matrix(1..2,1..3), see section Array Types
((1.1, 1.2, 1.3), (2.1, 2.2, 2.3)) (1 => (1.1, 1.2, 1.3), 2 => (2.1, 2.2, 2.3)) (1 => (1 => 1.1, 2 => 1.2, 3 => 1.3), 2 => (1 => 2.1, 2 => 2.2, 3 => 2.3))
A : Table := (7, 9, 5, 1, 3, 2, 4, 8, 6, 0); -- A(1)=7, A(10)=0 B : Table := (2 | 4 | 10 => 1, others => 0); -- B(1)=0, B(10)=1 C : constant Matrix := (1 .. 5 => (1 .. 8 => 0.0)); -- C'Last(1)=5, C'Last(2)=8
D : Bit_Vector(M .. N) := (M .. N => True); -- see section Array Types E : Bit_Vector(M .. N) := (others => True); F : String(1 .. 1) := (1 => 'F'); -- a one component aggregate: same as "F"
Syntax
expression ::=
relation {and relation} | relation {and then relation}
| relation {or relation} | relation {or else relation}
| relation {xor relation}
relation ::=
simple_expression [relational_operator simple_expression]
| simple_expression [not] in range
| simple_expression [not] in subtype_mark
simple_expression ::=
[unary_adding_operator] term {binary_adding_operator term}
term ::= factor {multiplying_operator factor}
factor ::= primary [** primary] | abs primary | not primary
primary ::=
numeric_literal | null
| string_literal | aggregate
| name | qualified_expression
| allocator | (expression)
Name Resolution Rules
Static Semantics
Dynamic Semantics
Implementation Permissions
Examples
4.0 -- real literal Pi -- named number (1 .. 10 => 0) -- array aggregate Sum -- variable Integer'Last -- attribute Sine(X) -- function call Color'(Blue) -- qualified expression Real(M*N) -- conversion (Line_Count + 10) -- parenthesized expression
Volume -- primary not Destroyed -- factor 2*Line_Count -- term -4.0 -- simple expression -4.0 + A -- simple expression B**2 - 4.0*A*C -- simple expression Password(1 .. 3) = "Bwv" -- relation Count in Small_Int -- relation Count not in Small_Int -- relation Index = 0 or Item_Hit -- expression (Cold and Sunny) or Warm -- expression (parentheses are required) A**(B**C) -- expression (parentheses are required)
Syntax
logical_operator ::= and | or | xor
relational_operator ::= = | /= | < | <= | > | >=
binary_adding_operator ::= + | - | &
unary_adding_operator ::= + | -
multiplying_operator ::= * | / | mod | rem
highest_precedence_operator ::= ** | abs | not
Static Semantics
Dynamic Semantics
Implementation Requirements
Implementation Permissions
Examples
not Sunny or Warm -- same as (not Sunny) or Warm X > 4.0 and Y > 0.0 -- same as (X > 4.0) and (Y > 0.0)
-4.0*A**2 -- same as -(4.0 * (A**2)) abs(1 + A) + B -- same as (abs (1 + A)) + B Y**(-3) -- parentheses are necessary A / B * C -- same as (A/B)*C A + (B + C) -- evaluate B + C before adding it to A
Name Resolution Rules
Static Semantics
function "and"(Left, Right : T) return T function "or" (Left, Right : T) return T function "xor"(Left, Right : T) return T
Dynamic Semantics
A B (A and B) (A or B) (A xor B) True True True True False True False False True True False True False True True False False False False False
Examples
Sunny or Warm Filter(1 .. 10) and Filter(15 .. 24) -- see section Index Constraints and Discrete Ranges
Next_Car.Owner /= null and then Next_Car.Owner.Age > 25 -- see section Incomplete Type Declarations N = 0 or else A(N) = Hit_Value
Name Resolution Rules
Legality Rules
Static Semantics
function "=" (Left, Right : T) return Boolean function "/="(Left, Right : T) return Boolean
function "<" (Left, Right : T) return Boolean function "<="(Left, Right : T) return Boolean function ">" (Left, Right : T) return Boolean function ">="(Left, Right : T) return Boolean
Dynamic Semantics
Examples
X /= Y
"" < "A" and "A" < "Aa" -- True "Aa" < "B" and "A" < "A " -- True
My_Car = null -- true if My_Car has been set to null (see section Incomplete Type Declarations) My_Car = Your_Car -- true if we both share the same car My_Car.all = Your_Car.all -- true if the two cars are identical
N not in 1 .. 10 -- range membership test Today in Mon .. Fri -- range membership test Today in Weekday -- subtype membership test (see section Enumeration Types) Archive in Disk_Unit -- subtype membership test, see section Variant Parts and Discrete Choices Tree.all in Addition'Class -- class membership test (see section Type Extensions)
Static Semantics
function "+"(Left, Right : T) return T function "-"(Left, Right : T) return T
function "&"(Left : T; Right : T) return T function "&"(Left : T; Right : C) return T function "&"(Left : C; Right : T) return T function "&"(Left : C; Right : C) return T
Dynamic Semantics
Examples
Z + 0.1 -- Z has to be of a real type
"A" & "BCD" -- concatenation of two string literals 'A' & "BCD" -- concatenation of a character literal and a string literal 'A' & 'A' -- concatenation of two character literals
Static Semantics
function "+"(Right : T) return T function "-"(Right : T) return TNOTES
Static Semantics
function "*" (Left, Right : T) return T function "/" (Left, Right : T) return T function "mod"(Left, Right : T) return T function "rem"(Left, Right : T) return T
A = (A/B)*B + (A rem B)
(-A)/B = -(A/B) = A/(-B)
A = B*N + (A mod B)
function "*"(Left, Right : T) return T function "/"(Left, Right : T) return T
function "*"(Left : T; Right : Integer) return T function "*"(Left : Integer; Right : T) return T function "/"(Left : T; Right : Integer) return T
function "*"(Left, Right : root_real) return root_real function "/"(Left, Right : root_real) return root_real
function "*"(Left : root_real; Right : root_integer) return root_real function "*"(Left : root_integer; Right : root_real) return root_real function "/"(Left : root_real; Right : root_integer) return root_real
function "*"(Left, Right : universal_fixed) return universal_fixed function "/"(Left, Right : universal_fixed) return universal_fixed
Legality Rules
Dynamic Semantics
A rem (-B) = A rem B (-A) rem B = -(A rem B)
A mod B = (A + K*B) mod B
A B A/B A rem B A mod B A B A/B A rem B A mod B
10 5 2 0 0 -10 5 -2 0 0 11 5 2 1 1 -11 5 -2 -1 4 12 5 2 2 2 -12 5 -2 -2 3 13 5 2 3 3 -13 5 -2 -3 2 14 5 2 4 4 -14 5 -2 -4 1
A B A/B A rem B A mod B A B A/B A rem B A mod B 10 -5 -2 0 0 -10 -5 2 0 0 11 -5 -2 1 -4 -11 -5 2 -1 -1 12 -5 -2 2 -3 -12 -5 2 -2 -2 13 -5 -2 3 -2 -13 -5 2 -3 -3 14 -5 -2 4 -1 -14 -5 2 -4 -4
Examples
I : Integer := 1; J : Integer := 2; K : Integer := 3;
X : Real := 1.0; -- see section Floating Point Types Y : Real := 2.0;
F : Fraction := 0.25; -- see section Fixed Point Types G : Fraction := 0.5;
Expression Value Result Type
I*J 2 same as I and J, that is, Integer
K/J 1 same as K and J, that is, Integer
K mod J 1 same as K and J, that is, Integer
X/Y 0.5 same as X and Y, that is, Real
F/2 0.125 same as F, that is, Fraction
3*F 0.75 same as F, that is, Fraction
0.75*G 0.375 universal_fixed, implicitly convertible
to any fixed point type
Fraction(F*G) 0.125 Fraction, as stated by the conversion
Real(J)*Y 4.0 Real, the type of both operands after
conversion of J
Static Semantics
function "abs"(Right : T) return T
function "not"(Right : T) return T
function "**"(Left : T; Right : Natural) return T
function "**"(Left : T; Right : Integer'Base) return T
Implementation Permissions
Syntax
type_conversion ::=
subtype_mark(expression)
| subtype_mark(name)
Name Resolution Rules
Legality Rules
Static Semantics
Dynamic Semantics
Examples
Real(2*J) -- value is converted to floating point Integer(1.6) -- value is 2 Integer(-0.4) -- value is 0
type A_Form is new B_Form;
X : A_Form; Y : B_Form;
X := A_Form(Y); Y := B_Form(X); -- the reverse conversion
type Sequence is array (Integer range <>) of Integer; subtype Dozen is Sequence(1 .. 12); Ledger : array(1 .. 100) of Integer;
Sequence(Ledger) -- bounds are those of Ledger Sequence(Ledger(31 .. 42)) -- bounds are 31 and 42 Dozen(Ledger(31 .. 42)) -- bounds are those of Dozen
Syntax
qualified_expression ::= subtype_mark'(expression) | subtype_mark'aggregate
Name Resolution Rules
Dynamic Semantics
Examples
type Mask is (Fix, Dec, Exp, Signif); type Code is (Fix, Cla, Dec, Tnz, Sub);
Print (Mask'(Dec)); -- Dec is of type Mask Print (Code'(Dec)); -- Dec is of type Code
for J in Code'(Fix) .. Code'(Dec) loop ... -- qualification needed for either Fix or Dec for J in Code range Fix .. Dec loop ... -- qualification unnecessary for J in Code'(Fix) .. Dec loop ... -- qualification unnecessary for Dec
Dozen'(1 | 3 | 5 | 7 => 2, others => 0) -- see section Type Conversions
Syntax
allocator ::= new subtype_indication | new qualified_expression
Name Resolution Rules
Legality Rules
Static Semantics
Dynamic Semantics
Examples
new Cell'(0, null, null) -- initialized explicitly, see section Incomplete Type Declarations new Cell'(Value => 0, Succ => null, Pred => null) -- initialized explicitly new Cell -- not initialized
new Matrix(1 .. 10, 1 .. 20) -- the bounds only are given new Matrix'(1 .. 10 => (1 .. 20 => 0.0)) -- initialized explicitly
new Buffer(100) -- the discriminant only is given new Buffer'(Size => 80, Pos => 0, Value => (1 .. 80 => 'A')) -- initialized explicitly
Expr_Ptr'(new Literal) -- allocator for access-to-class-wide type, see section Type Extensions Expr_Ptr'(new Literal'(Expression with 3.5)) -- initialized explicitly
Legality Rules
Implementation Requirements
Examples
1 + 1 -- 2 abs(-10)*3 -- 30
Kilo : constant := 1000; Mega : constant := Kilo*Kilo; -- 1_000_000 Long : constant := Float'Digits*2;
Half_Pi : constant := Pi/2; -- see section Number Declarations. Deg_To_Rad : constant := Half_Pi/90; Rad_To_Deg : constant := 1.0/Deg_To_Rad; -- equivalent to 1.0/((3.14159_26536/2)/90)
Static Semantics
Syntax
sequence_of_statements ::= statement {statement}
statement ::=
{label} simple_statement | {label} compound_statement
simple_statement ::= null_statement | assignment_statement | exit_statement | goto_statement | procedure_call_statement | return_statement | entry_call_statement | requeue_statement | delay_statement | abort_statement | raise_statement | code_statement
compound_statement ::=
if_statement | case_statement
| loop_statement | block_statement
| accept_statement | select_statement
null_statement ::= null;
label ::= <<label_statement_identifier>>
statement_identifier ::= direct_name
Name Resolution Rules
Legality Rules
Static Semantics
Dynamic Semantics
Examples
<<Here>> <<Ici>> <<Aqui>> <<Hier>> null;
<<After>> X := 1;
Syntax
assignment_statement ::= variable_name := expression;
Name Resolution Rules
Legality Rules
Dynamic Semantics
Examples
Value := Max_Value - 1; Shade := Blue;
Next_Frame(F)(M, N) := 2.5; -- see section Indexed Components U := Dot_Product(V, W); -- see section Subprogram Bodies
Writer := (Status => Open, Unit => Printer, Line_Count => 60); -- see section Variant Parts and Discrete Choices Next_Car.all := (72074, null); -- see section Incomplete Type Declarations
I, J : Integer range 1 .. 10 := 5; K : Integer range 1 .. 20 := 15; ...
I := J; -- identical ranges K := J; -- compatible ranges J := K; -- will raise Constraint_Error if K > 10
A : String(1 .. 31); B : String(3 .. 33); ...
A := B; -- same number of components
A(1 .. 9) := "tar sauce"; A(4 .. 12) := A(1 .. 9); -- A(1 .. 12) = "tartar sauce"NOTES
Syntax
if_statement ::=
if condition then
sequence_of_statements
{elsif condition then
sequence_of_statements}
[else
sequence_of_statements]
end if;
condition ::= boolean_expression
Name Resolution Rules
Dynamic Semantics
Examples
if Month = December and Day = 31 then Month := January; Day := 1; Year := Year + 1; end if;
if Line_Too_Short then raise Layout_Error; elsif Line_Full then New_Line; Put(Item); else Put(Item); end if;
if My_Car.Owner.Vehicle /= My_Car then -- see section Incomplete Type Declarations Report ("Incorrect data"); end if;
Syntax
case_statement ::=
case expression is
case_statement_alternative
{case_statement_alternative}
end case;
case_statement_alternative ::=
when discrete_choice_list =>
sequence_of_statements
Name Resolution Rules
Legality Rules
Dynamic Semantics
Examples
case Sensor is when Elevation => Record_Elevation(Sensor_Value); when Azimuth => Record_Azimuth (Sensor_Value); when Distance => Record_Distance (Sensor_Value); when others => null; end case;
case Today is when Mon => Compute_Initial_Balance; when Fri => Compute_Closing_Balance; when Tue .. Thu => Generate_Report(Today); when Sat .. Sun => null; end case;
case Bin_Number(Count) is
when 1 => Update_Bin(1);
when 2 => Update_Bin(2);
when 3 | 4 =>
Empty_Bin(1);
Empty_Bin(2);
when others => raise Error;
end case;
Syntax
loop_statement ::=
[loop_statement_identifier:]
[iteration_scheme] loop
sequence_of_statements
end loop [loop_identifier];
iteration_scheme ::= while condition | for loop_parameter_specification
loop_parameter_specification ::= defining_identifier in [reverse] discrete_subtype_definition
Static Semantics
Dynamic Semantics
for J in reverse 1 .. 0 for J in 0 .. 1
Examples
loop Get(Current_Character); exit when Current_Character = '*'; end loop;
while Bid(N).Price < Cut_Off.Price loop Record_Bid(Bid(N).Price); N := N + 1; end loop;
for J in Buffer'Range loop -- works even with a null range
if Buffer(J) /= Space then
Put(Buffer(J));
end if;
end loop;
Summation: while Next /= Head loop -- see section Incomplete Type Declarations Sum := Sum + Next.Value; Next := Next.Succ; end loop Summation;
Syntax
block_statement ::=
[block_statement_identifier:]
[declare
declarative_part]
begin
handled_sequence_of_statements
end [block_identifier];
Static Semantics
Dynamic Semantics
Examples
Swap:
declare
Temp : Integer;
begin
Temp := V; V := U; U := Temp;
end Swap;
Syntax
exit_statement ::= exit [loop_name] [when condition];
Name Resolution Rules
Legality Rules
Dynamic Semantics
Examples
for N in 1 .. Max_Num_Items loop Get_New_Item(New_Item); Merge_Item(New_Item, Storage_File); exit when New_Item = Terminal_Item; end loop;
Main_Cycle:
loop
-- initial statements
exit Main_Cycle when Found;
-- final statements
end loop Main_Cycle;
Syntax
goto_statement ::= goto label_name;
Name Resolution Rules
Legality Rules
Dynamic Semantics
Examples
<<Sort>>
for I in 1 .. N-1 loop
if A(I) > A(I+1) then
Exchange(A(I), A(I+1));
goto Sort;
end if;
end loop;
Syntax
subprogram_declaration ::= subprogram_specification;
abstract_subprogram_declaration ::= subprogram_specification is abstract;
subprogram_specification ::=
procedure defining_program_unit_name parameter_profile
| function defining_designator parameter_and_result_profile
designator ::= [parent_unit_name . ]identifier | operator_symbol
defining_designator ::= defining_program_unit_name | defining_operator_symbol
defining_program_unit_name ::= [parent_unit_name . ]defining_identifier
operator_symbol ::= string_literal
defining_operator_symbol ::= operator_symbol
parameter_profile ::= [formal_part]
parameter_and_result_profile ::= [formal_part] return subtype_mark
formal_part ::=
(parameter_specification {; parameter_specification{)
parameter_specification ::=
defining_identifier_list : mode subtype_mark
[:= default_expression]
| defining_identifier_list : access_definition
[:= default_expression]
mode ::= [in] | in out | out
Name Resolution Rules
Legality Rules
Static Semantics
Dynamic Semantics
Examples
procedure Traverse_Tree; procedure Increment(X : in out Integer); procedure Right_Indent(Margin : out Line_Size); -- see section Integer Types procedure Switch(From, To : in out Link); -- see section Incomplete Type Declarations
function Random return Probability; -- see section Floating Point Types
function Min_Cell(X : Link) return Cell; -- see section Incomplete Type Declarations function Next_Frame(K : Positive) return Frame; -- see section Access Types function Dot_Product(Left, Right : Vector) return Real; -- see section Array Types
function "*"(Left, Right : Matrix) return Matrix; -- see section Array Types
procedure Print_Header (Pages : in Natural; Header : in Line := (1 .. Line'Last => ' '); -- see section Array Types Center : in Boolean := True);
Static Semantics
Bounded (Run-Time) Errors
Syntax
subprogram_body ::=
subprogram_specification is
declarative_part
begin
handled_sequence_of_statements
end [designator];
Legality Rules
Static Semantics
Dynamic Semantics
Examples
procedure Push(E : in Element_Type; S : in out Stack) is
begin
if S.Index = S.Size then
raise Stack_Overflow;
else
S.Index := S.Index + 1;
S.Space(S.Index) := E;
end if;
end Push;
function Dot_Product(Left, Right : Vector) return Real is
Sum : Real := 0.0;
begin
Check(Left'First = Right'First and Left'Last = Right'Last);
for J in Left'Range loop
Sum := Sum + Left(J)*Right(J);
end loop;
return Sum;
end Dot_Product;
Static Semantics
Implementation Permissions
Syntax
pragma Inline(name {, name{);
Legality Rules
Static Semantics
Implementation Permissions
Syntax
procedure_call_statement ::=
procedure_name;
| procedure_prefix actual_parameter_part;
function_call ::=
function_name
| function_prefix actual_parameter_part
actual_parameter_part ::=
(parameter_association {, parameter_association{)
parameter_association ::= [formal_parameter_selector_name =>] explicit_actual_parameter
explicit_actual_parameter ::= expression | variable_name
Name Resolution Rules
Dynamic Semantics
Examples
Traverse_Tree; -- see section Subprogram Declarations Print_Header(128, Title, True); -- see section Subprogram Declarations
Switch(From => X, To => Next); -- see section Subprogram Declarations. Print_Header(128, Header => Title, Center => True); -- see section Subprogram Declarations. Print_Header(Header => Title, Center => True, Pages => 128); -- see section Subprogram Declarations.
Dot_Product(U, V) -- see section Subprogram Declarations, and section Subprogram Bodies. Clock -- see section Delay Statements, Duration, and Time. F.all -- presuming F is of an access-to-subprogram type -- see section Access Types.
procedure Activate(Process : in Process_Name;
After : in Process_Name := No_Process;
Wait : in Duration := 0.0;
Prior : in Boolean := False);
procedure Pair(Left, Right : in Person_Name := new Person); -- see section Incomplete Type Declarations.
Activate(X); Activate(X, After => Y); Activate(X, Wait => 60.0, Prior => True); Activate(X, Y, 10.0, False);
Pair; Pair(Left => new Person, Right => new Person);NOTES
Examples
procedure Put(X : in Integer); procedure Put(X : in String);
procedure Set(Tint : in Color); procedure Set(Signal : in Light);
Put(28);
Put("no possible ambiguity here");
Set(Tint => Red); Set(Signal => Red); Set(Color'(Red));
-- Set(Red) would be ambiguous since Red may -- denote a value either of type Color or of type Light
Name Resolution Rules
Legality Rules
Dynamic Semantics
Syntax
return_statement ::= return [expression];
Name Resolution Rules
Legality Rules
Dynamic Semantics
Examples
return; -- in a procedure body, entry_body, or accept_statement return Key_Value(Last_Index); -- in a function body
Name Resolution Rules
Legality Rules
Static Semantics
Examples
function "+" (Left, Right : Matrix) return Matrix; function "+" (Left, Right : Vector) return Vector; -- assuming that A, B, and C are of the type Vector -- the following two statements are equivalent: A := B + C; A := "+"(B, C);
Syntax
package_declaration ::= package_specification;
package_specification ::=
package defining_program_unit_name is
{basic_declarative_item}
[private
{basic_declarative_item}]
end [[parent_unit_name.]identifier]
Legality Rules
Static Semantics
Dynamic Semantics
Examples
package Rational_Numbers is
type Rational is
record
Numerator : Integer;
Denominator : Positive;
end record;
function "="(X,Y : Rational) return Boolean;
function "/" (X,Y : Integer) return Rational; -- to construct a rational number
function "+" (X,Y : Rational) return Rational; function "-" (X,Y : Rational) return Rational; function "*" (X,Y : Rational) return Rational; function "/" (X,Y : Rational) return Rational; end Rational_Numbers;
Syntax
package_body ::=
package body defining_program_unit_name is
declarative_part
[begin
handled_sequence_of_statements]
end [[parent_unit_name.]identifier];
Legality Rules
Static Semantics
Dynamic Semantics
Examples
package body Rational_Numbers is
procedure Same_Denominator (X,Y : in out Rational) is
begin
-- reduces X and Y to the same denominator:
...
end Same_Denominator;
function "="(X,Y : Rational) return Boolean is
U : Rational := X;
V : Rational := Y;
begin
Same_Denominator (U,V);
return U.Numerator = V.Numerator;
end "=";
function "/" (X,Y : Integer) return Rational is
begin
if Y > 0 then
return (Numerator => X, Denominator => Y);
else
return (Numerator => -X, Denominator => -Y);
end if;
end "/";
function "+" (X,Y : Rational) return Rational is ... end "+"; function "-" (X,Y : Rational) return Rational is ... end "-"; function "*" (X,Y : Rational) return Rational is ... end "*"; function "/" (X,Y : Rational) return Rational is ... end "/";
end Rational_Numbers;
Syntax
private_type_declaration ::=
type defining_identifier [discriminant_part] is
[[abstract] tagged] [limited] private;
private_extension_declaration ::=
type defining_identifier [discriminant_part] is
[abstract] new ancestor_subtype_indication with private;
Legality Rules
Static Semantics
Dynamic Semantics
Examples
type Key is private; type File_Name is limited private;
type List is new Ada.Finalization.Controlled with private;
Static Semantics
Denotes the class-wide subtype corresponding to the full view of S. This attribute is allowed only from the beginning of the private part in which the full view is declared, until the declaration of the full view. After the full view, the Class attribute of the full view can be used.NOTES
Examples
package Key_Manager is type Key is private; Null_Key : constant Key; -- a deferred constant declaration, see section Deferred Constants procedure Get_Key(K : out Key); function "<" (X, Y : Key) return Boolean; private type Key is new Natural; Null_Key : constant Key := Key'First; end Key_Manager;
package body Key_Manager is
Last_Key : Key := Null_Key;
procedure Get_Key(K : out Key) is
begin
Last_Key := Last_Key + 1;
K := Last_Key;
end Get_Key;
function "<" (X, Y : Key) return Boolean is
begin
return Natural(X) < Natural(Y);
end "<";
end Key_Manager;
NOTES
Legality Rules
Dynamic Semantics
Examples
Null_Key : constant Key; -- see section Private Operations
CPU_Identifier : constant String(1..8); pragma Import(Assembler, CPU_Identifier, Link_Name => "CPU_ID"); -- see section Interfacing Pragmas
Legality Rules
Static Semantics
Examples
package IO_Package is type File_Name is limited private;
procedure Open (F : in out File_Name);
procedure Close(F : in out File_Name);
procedure Read (F : in File_Name; Item : out Integer);
procedure Write(F : in File_Name; Item : in Integer);
private
type File_Name is
limited record
Internal_Name : Integer := 0;
end record;
end IO_Package;
package body IO_Package is Limit : constant := 200; type File_Descriptor is record ... end record; Directory : array (1 .. Limit) of File_Descriptor; ... procedure Open (F : in out File_Name) is ... end; procedure Close(F : in out File_Name) is ... end; procedure Read (F : in File_Name; Item : out Integer) is ... end; procedure Write(F : in File_Name; Item : in Integer) is ... end; begin ... end IO_Package;NOTES
Static Semantics
package Ada.Finalization is
pragma Preelaborate(Finalization);
type Controlled is abstract tagged private;
procedure Initialize(Object : in out Controlled);
procedure Adjust (Object : in out Controlled);
procedure Finalize (Object : in out Controlled);
type Limited_Controlled is abstract tagged limited private;
procedure Initialize(Object : in out Limited_Controlled);
procedure Finalize (Object : in out Limited_Controlled);
private
... -- not specified by the language
end Ada.Finalization;
Dynamic Semantics
Implementation Permissions
Dynamic Semantics
Bounded (Run-Time) Errors
Static Semantics
Static Semantics
Static Semantics
Name Resolution Rules
Legality Rules