Expressions and references
This chapter discusses the various types of expressions and references.
An expression is a representation of a value. An expression can be one of the following:
- A single constant, variable, or function reference
- Any combination of constants, variables, or function references, including operators and parentheses used in the combination
An expression that contains operators is an operational expression.
The constants and variables of an operational expression are called operands. See Operational expressions for more information.
The following diagram shows the syntax for expressions and references.
- 1 Operators are shown in Table 2.
- 2 Locator-qualifier is described under Locator qualification and Typed structure qualification.
- 3 Subscripts are described under Arrays.
- 4 Arguments are described in Passing arguments to procedures.
- 5 Qualified-reference is described under Structure and union qualification.
- 6 Identifiers are described under Identifiers.
Any expression can be classified as an element expression (also called a scalar expression), an array expression, or a structure expression. Element variables and array variables can appear in the same expression.
- An element expression
- Represents a single value. This definition includes an elementary name within a structure or a union or a subscripted name that specifies a single element of an array.
- An array expression
- Represents an array of values. This definition includes a member of a structure or union that has the dimension attribute.
- A structure expression
- Represents a structured set of values.
Consider the following example:
dcl A(10,10) bin fixed(31),
B(10,10) bin fixed(31),
1 Rate,
2 Primary dec fixed(4,2),
2 Secondary dec fixed(4,2),
1 Cost(2),
2 Primary dec fixed(4,2),
2 Secondary dec fixed(4,2),
C bin fixed(15),
D bin fixed(15);
dcl Pi bin float value(3.1416);
These are element expressions:
Pi
27
C
C * D
A(3,2) + B(4,8)
Rate.Primary - Cost.Primary(1)
A(4,4) * C
Rate.Secondary / 4
A(4,6) * Cost.Secondary(2)
sum(A)
addr(Rate)
These are array expressions:
A
A + B
A * C - D
B / 10B
The syntax of many PL/I statements allows expressions, provided the result of the expression conforms with the syntax rules. Unless specifically stated in the text following the syntax specification, the unqualified term expression or reference refers to a scalar expression. For expressions other than a scalar expression, the type of expression is noted. For example, the term array expression indicates that a scalar expression is not valid.
Here is an example of a structure expression:
Rate = Rate*2
