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:
if ( name = 'Jane' ) & ( password = 'shazam' ) then /* check user and password */ |
if ( name = 'Jane' ) & ( password = 'shazam' ) then /* check user and password */
A token is one of the following:
Warning: a left parenthesis that immediately follows a literal string, or a symbol reference, alters the syntactic meaning of the term. It becomes a function call instead. n = length( 'shazam' )The word length above is considered to be a function invocation. n = 'LENGTH'( 'shazam' )The literal string 'LENGTH' above is considered to be a function invocation. |
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.
say length( '' ) |
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"XSpaces can appear between hexadecimal digits.
'2 2b ad'xSpaces must appear at a boundary that is appropriate for pairs of hexadecimal digits.
'2 2bad'XThe first sequence of hexadecimal digits can contain an odd number of digits.
'22b ad'xThe 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
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'xwould be converted to
'02 2B AD'xThe literal string would contain the following values:
+----+----+----+ | 02 | 2B | AD | +----+----+----+ +0 +1 +2
'22BAD'xis 3 -- it is stored in 3 bytes.
When there are no hexadecimal digits between the quotes, the length of the string is 0.
say length( ''x ) |
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"BSpaces can appear between binary digits.
'1 0111'bSpaces must appear at a boundary that is appropriate for quadruples of binary digits.
'1 0111 1100'BThe first sequence of binary digits can contain an odd number of digits.
'10111 1100'bThe 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
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'bwould be prefixed with 3 leading zero digits
'0001 1101'band then converted to
'1D'x
The length of the binary string
'11101'bis 1 -- it is stored in 1 byte.
When there are no binary digits between the quotes, the length of the string is 0.
say length( ''b ) |
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.
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.
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.
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.