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
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
indexed_component ::= prefix(expression {, expression})Name Resolution Rules
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
slice ::= prefix(discrete_range)Name Resolution Rules
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
selected_component ::= prefix . selector_name
selector_name ::= identifier | character_literal | operator_symbolName Resolution Rules
Dynamic Semantics
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)
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
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)
3.14159_26536 -- a real literal 1_345 -- an integer literal 'A' -- a character literal "Some Text" -- a string literal
aggregate ::= record_aggregate | extension_aggregate | array_aggregateName Resolution Rules
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
(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)
extension_aggregate ::= (ancestor_part with record_component_association_list)
ancestor_part ::= expression | subtype_markName Resolution Rules
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
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
(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"
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
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)
logical_operator ::= and | or | xor
relational_operator ::= = | /= | < | <= | > | >=
binary_adding_operator ::= + | - | &
unary_adding_operator ::= + | -
multiplying_operator ::= * | / | mod | rem
highest_precedence_operator ::= ** | abs | notStatic Semantics
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
function "and"(Left, Right : T) return T function "or" (Left, Right : T) return T function "xor"(Left, Right : T) return T
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 FalseExamples
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
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 BooleanDynamic Semantics
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 TDynamic Semantics
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_fixedLegality Rules
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 -4Examples
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
type_conversion ::= subtype_mark(expression) | subtype_mark(name)
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
qualified_expression ::= subtype_mark'(expression) | subtype_mark'aggregateName Resolution Rules
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
allocator ::= new subtype_indication | new qualified_expressionName Resolution Rules
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
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
Go to the first, previous, next, last section, table of contents.