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.

Read syntax diagramSkip visual syntax diagramunary-expression infix-operator1 unary-expression
unary-expression
Read syntax diagramSkip visual syntax diagramprefix-operator1elementary-expression
elementary-expression
Read syntax diagramSkip visual syntax diagram( expression)referenceconstant
reference
Read syntax diagramSkip visual syntax diagramlocator-qualifier2basic-reference(subscript-list3)(argument-list4)
locator-qualifier
Read syntax diagramSkip visual syntax diagram2reference ->  =>  . 
basic-reference
Read syntax diagramSkip visual syntax diagramqualified-reference5identifier6
subscript-list
Read syntax diagramSkip visual syntax diagram3,expression*
argument-list
Read syntax diagramSkip visual syntax diagram4,expression*
qualified-reference
Read syntax diagramSkip visual syntax diagram5basic-reference(subscript-list).
Notes:

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