COBOL Manual for TNS/E Programs (H06.03+)

Procedure Division
HP COBOL Manual for TNS/E Programs520347-003
8-47
Arithmetic Expressions
A plus (+) or minus (-) appearing as the first character of a numeric literal is the sign
character of that literal, not an arithmetic operator. For example, +2 is not an arithmetic
expression. In contrast, a plus (+) or minus (-) followed by a separator is interpreted as
a binary operator when preceded by an operand or as a unary operator when not
preceded by an operand. For example, X + 2 represents a simple arithmetic
expression. The presence of a sign character in a numeric literal does not affect its use
as an operand; therefore, both X + + 2 and X + 2 are valid and, in this case, equivalent
expressions.
Formation and Evaluation Rules
Parentheses can be used to specify the order in which the elements of an expression
are to be evaluated. Expressions within parentheses are evaluated first. Within nested
parentheses, evaluation proceeds from the least inclusive set to the most inclusive set.
When parentheses are not used, or parenthesized expressions are at the same level of
inclusiveness, the hierarchical order of execution is shown in Table 8-14.
When no parentheses are present to specify otherwise, the order of execution of
consecutive operations of the same hierarchical level is from left to right.
Table 8-15 shows some expressions that appear to be ambiguous and the COBOL
interpretation of them.
Table 8-14. Hierarchy of Operators
Hierarchy Operators
1st Unary plus and minus
2nd Exponentiation
3rd Multiplication and division
4th Addition and subtraction
Table 8-15. Precedence in Arithmetic Expressions
Ambiguous Interpretation
A / B
* C (A / B) * C
A / B / C (A / B) / C
A
** B ** C(A ** B) ** C
A + B / C + D
** E * F - G ((A + (B / C)) + ((D ** E) * F)) - G