Kilowatt Software L.L.C.
Classic Rexx Tutorial
Language Level 4.00 (TRL-2)

Instruction elements

A Rexx instruction consists of one or more syntax elements. Multiple elements within an instruction are separated by spaces, comments, special characters, or expression operators until an instruction terminator is encountered. Some elements are keywords, which either determine the current instruction's type, or are significant within the instruction's context. An instruction is classified by a series of rules. The remaining elements in an instruction are tokens.

Here is an example of a Rexx instruction:

The syntax elements in this instruction are:
  if
  (
  name
  =
  'Jane'
  )
  &
  (
  password
  =
  'shazam'
  )
  then
  /* check user and password */

In the instruction:


Tokens

A token is one of the following:


Literal string

A literal string is delimited by a pair of quote characters. Either single or double quotes can be used to delimit the string.

  'This is a fine literal string'
  "This is another fine literal string"
  "Isn't the weather nice!"
Within the string any characters can appear.
 'thisIsNotALabel : abra * ca + dabra, or shazam ; and more...'
When the same type of quote (as the delimiting quote) is required within the string, then that type of quote is doubled.
  'Don''t even think about it!'
  """To be, or not to be, that is the question."""
The literal string is empty when there are no characters between the quotes. The length of the string is 0.


Hexadecimal string

When a quoted string is immediately followed by an 'X' (or an 'x'), then the string is a hexadecimal string. Between the quotes a series of zero or more hexadecimal digits (0-9, a-f, A-F) are specified.

  '22bad'x
  "22BAD"X
Spaces can appear between hexadecimal digits.
 '2  2b  ad'x
Spaces must appear at a boundary that is appropriate for pairs of hexadecimal digits.
  '2 2bad'X
The first sequence of hexadecimal digits can contain an odd number of digits.
  '22b ad'x
The following is incorrect. All sequences of hexadecimal digits, after the first sequence, must have lengths that are a multiple of 2.
  '2 2ba d'X

Hexadecimal literal value

The value of a hexadecimal string is a literal string, which is a packed series of bytes. If the number of hexadecimal digits in the hexadecimal string is odd, it is prefixed by a leading hexadecimal '0'x. Then, pairs of hexadecimal digits are packed into the resulting literal string from left to right. Thus, the value

'22BAD'x
would be converted to
'02 2B AD'x
The literal string would contain the following values:
  +----+----+----+
  | 02 | 2B | AD |
  +----+----+----+
  +0   +1   +2

The length of the hexadecimal string
'22BAD'x
is 3 -- it is stored in 3 bytes.

When there are no hexadecimal digits between the quotes, the length of the string is 0.


Binary string

When a quoted string is immediately followed by a 'B' (or a 'b'), then the string is a binary string. Between the quotes a series of zero or more binary digits (0 or 1) are specified.

  '10111'b
  "10111"B
Spaces can appear between binary digits.
  '1  0111'b
Spaces must appear at a boundary that is appropriate for quadruples of binary digits.
  '1  0111  1100'B
The first sequence of binary digits can contain an odd number of digits.
  '10111  1100'b
The following is incorrect. All sequences of binary digits, after the first sequence, must have lengths that are a multiple of 4.
  '1 01111  100'B

Binary literal value

The value of a binary string is a literal string, which is a packed series of bytes. If the number of binary digits in the binary string is not a multiple of 8, it is prefixed by sufficient leading '0'b binary digits. The binary digits are then converted to a hexadecimal string, four bits per hexadecimal digit. Then, the hexadecimal string is converted to a literal string as described in the hexadecimal string section above. The value

'11101'b
would be prefixed with 3 leading zero digits
'0001 1101'b
and then converted to
'1D'x

The length of the binary string

'11101'b
is 1 -- it is stored in 1 byte.

When there are no binary digits between the quotes, the length of the string is 0.


Symbol

Rexx symbols are sequences of numbers, letters, and the characters: . ! ? and _. These are either numeric values or potential variable references. These are described in detail on a separate page -- click here.


Operator characters

A Rexx expression operator is formed from one or more of the following characters:

  +  -  *  /  %  |  =  ¬  \  <  >  &  (  )  

In some contexts a space character can also be a concatenation operator.

Special characters

The following characters are treated specially within an instruction.

  ,  ;  :

A comma is used for multiple purposes:

A semicolon is an instruction terminator

A colon is used in labels

In addition a right parenthesis is special -- denoting the end of an expression, or function call.


Tabs and spaces -- implementation-dependent note

Text values that contain tab characters can be problematic for Rexx programs. When printed, a tab character may appear as one or more spaces. At the end of a text value, the tab character is invisible. In the following contexts difficulties ensue if a tab character is not considered equivalent to a space character.

Special implementation support is required to treat a tab character equivalent to a space. Some implementations never consider a tab character to be equal to a space. Some implementations always consider a tab character equivalent to a space.


Kilowatt Software L.L.C. -- Classic Rexx Tutorial -- Back to top
Click here if you have any comments or questions regarding this tutorial

Last updated on: 11 Apr 2006