[Home] [Prev] [Next] [Index]

4.4 Expressions

4.4 Expressions

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

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

3
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.

4
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.

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

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

7
References:

*
aggregate 4.3

*
allocator 4.8

*
array aggregate 4.3.2

*
attribute 4.1.4

*
binary adding operator 4.5

*
binary adding operator 4.5.3

*
context of overload resolution 8.7

*
exponentiating operator 4.5

*
exponentiating operator 4.5.6

*
function call 6.4

*
multiplying operator 4.5

*
multiplying operator 4.5.5

*
name 4.1

*
named number 3.2

*
null literal 3.8

*
numeric literal 2.4

*
object 3.2

*
operator 4.5

*
overloading 8.3

*
overloading an operator 6.7

*
qualified expression 4.7

*
range 3.5

*
real literal 2.4

*
relation 4.5.1

*
relational operator 4.5

*
relational operator 4.5.2

*
result type 6.1

*
string literal 2.6

*
type 3.3

*
type conversion 4.6

*
type mark 3.3.2

*
unary adding operator 4.5

*
unary adding operator 4.5.4

*
variable 3.2.1



[Home] [Prev] [Next] [Index]

documentation@rational.com
Copyright © 1993-2000, Rational Software Corporation. All rights reserved.