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 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 | 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)
References: aggregate, allocator, array aggregate, attribute, binary adding operator, and 4.5.3, context of overload resolution, exponentiating operator, and 4.5.6, function call, multiplying operator, and 4.5.5, name, named number, null literal, numeric literal, object, operator, overloading, overloading an operator, qualified expression, range, real literal, relation, relational operator, and 4.5.2, result type, string literal, type, type conversion, type mark, unary adding operator, and 4.5.4, variable.
Rationale references: 3.6 Expressions
Style Guide references: 2.1.1 Horizontal Spacing, 2.1.3 Alignment of Operators, 2.1.5 More on Alignment, 5.5 Expressions, 5.5.3 Parenthetical Expressions, 7.2.7 Subexpression Evaluation
Address any questions or comments to adainfo@sw-eng.falls-church.va.us.