Ada Reference ManualLegal Information
Contents   Index   References   Search   Previous   Next 

4.4 Expressions

1/3
An expression is a formula that defines the computation or retrieval of a value. In this International Standard, the term “expression” refers to a construct of the syntactic category expression or of any of the following categories: choice_expression, choice_relation, relation, simple_expression, term, factor, primary, conditional_expression, quantified_expression.

Syntax

2
expression ::= 
     relation {and relation}  | relation {and then relation}
   | relation {or relation}  | relation {or else relation}
   | relation {xor relation}
2.1/3
choice_expression ::= 
     choice_relation {and choice_relation}
   | choice_relation {or choice_relation}
   | choice_relation {xor choice_relation}
   | choice_relation {and then choice_relation}
   | choice_relation {or else choice_relation}
2.2/3
choice_relation ::= 
     simple_expression [relational_operator simple_expression]
3/4
relation ::= 
     simple_expression [relational_operator simple_expression]
   | tested_simple_expression [notin membership_choice_list
   | raise_expression
3.1/3
membership_choice_list ::= membership_choice {| membership_choice}
3.2/4
membership_choice ::= choice_simple_expression | range | subtype_mark
4
simple_expression ::= [unary_adding_operatorterm {binary_adding_operator term}
5
term ::= factor {multiplying_operator factor}
6
factor ::= primary [** primary] | abs primary | not primary
7/3
primary ::= 
   numeric_literal | null | string_literal | aggregate
 | name | allocator | (expression)
 | (conditional_expression) | (quantified_expression)

Name Resolution Rules

8
A name used as a primary shall resolve to denote an object or a value. 

Static Semantics

9
Each expression has a type; it specifies the computation or retrieval of a value of that type. 

Dynamic Semantics

10
The value of a primary that is a name denoting an object is the value of the object. 

Implementation Permissions

11
For the evaluation of a primary that is a name denoting an object of an unconstrained numeric subtype, if the value of the object is outside the base range of its type, the implementation may either raise Constraint_Error or return the value of the object.

Examples

12
Examples of primaries:
13
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 
14
Examples of expressions:
15/2
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
R*Sin(θ)*Cos(φ)             -- 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)

Contents   Index   References   Search   Previous   Next 
Ada-Europe Ada 2005 and 2012 Editions sponsored in part by Ada-Europe