Five binary and two unary arithmetic operators can be used in arithmetic expressions. They are represented by specific characters that must be preceded and followed by a space.
Parentheses are used to highlight or modify the order of evaluation of complex expressions. This improves both readability and maintainability.
Left and right parentheses must be paired in an arithmetic expression with the left parenthesis appearing before its corresponding right parenthesis.
Expressions within parentheses are evaluated first and parenthetical pairs can be nested within other pairs. Evaluation proceeds from the least inclusive pairing outward.
When the order of evaluation is not made explicit by parentheses, expressions are evaluated left-to-right following the hierarchy listed below:
An arithmetic expression may begin only with a left parenthesis, a unary operator, or an operand (that is, an identifier or a literal). It may end only with a right parenthesis or an operand. An arithmetic expression must contain at least one reference to an identifier or a literal.
If the first operator in an arithmetic expression is a unary operator, it must be immediately preceded by a left parenthesis if that arithmetic expression immediately follows an identifier or another arithmetic expression.
Table 19 shows permissible arithmetic symbol pairs. An arithmetic symbol pair is the combination of two such symbols in sequence. In the figure:
Table 19. Valid Arithmetic Symbol Pairs
|
| Second Symbol | ||||
| First Symbol | Identifier or Literal | * / ** + - | Unary + or Unary - | ( | ) |
| Identifier or Literal | No | Yes | No | No | Yes |
| * / ** + - | Yes | No | Yes | Yes | No |
| Unary + or Unary - | Yes | No | No | Yes | No |
| ( | Yes | No | Yes | Yes | No |
| ) | No | Yes | No | No | Yes |
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.