# Ada '83 Language Reference Manual

## 4.4. Expressions

An expression is a formula that defines the computation of a value.

```    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 type_mark

term ::= factor {multiplying_operator factor}

factor ::= primary [** primary] | abs primary | not primary

primary ::=
numeric_literal | null | aggregate | string_literal | name | allocator
| function_call | type_conversion | qualified_expression | (expression)
```

Each primary has a value and a type. The only names allowed as primaries are named numbers; attributes that yield values; and names denoting objects (the value of such a primary is the value of the object) or denoting values. Names that denote formal parameters of mode out are not allowed as primaries; names of their subcomponents are only allowed in the case of discriminants.

The type of an expression depends only on the type of its constituents and on the operators applied; for an overloaded constituent or operator, the determination of the constituent type, or the identification of the appropriate operator, depends on the context. For each predefined operator, the operand and result types are given in section 4.5.

Examples of primaries:

```    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
```

Examples of expressions:

```    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)
```

Rationale references: 3.6 Expressions