Sunday, September 20, 2009

Tutorial 2: REXX Syntax

Rexx is a free format language. It doesn’t have strict rules like Assembler, COBOL etc.

Rexx program must start with “REXX” within the first line (line 1) of the program. Usually, you will write /* REXX */ in the first line. Though if the first line is /* This is a REXX program */, it is perfectly valid.

You can have two REXX commands in the same line. They need to be delimited by semicolon - ;.

A = A + 1; B = B + 1; C = C + 1

A REXX instruction can be continued on the second line. Comma - , is used for this.
MESSAGE = ‘ This line is very long and needs to be continued’,
‘ on the second line’

The following are various symbols used.

Arithmetic Operators

+ Add
- Subtract
* Multiply
/ Divide
% Divide and return a whole number without a remainder
// Divide and return the remainder only
** Raise a number to a whole number power
-number Negate the number
+number Add the number to 0

Logical Operators

& AND
| Inclusive OR
&& Exclusive OR
\ Logical NOT

Comparison Operators
== Strictly Equal : The two strings must be identical (character by character) and of the same length to be considered strictly equal. Eg. “ “ == “ “ is false.

= Equal
\== Not strictly equal
\= Not equal
> Greater than
< Less than
><>
>= Greater than or equal to
\< Not less than
<= Less than or equal to
\> Not greater than

The not character, "¬", is same as the backslash ("\").

A REXX symbol or variable can consist of
A...Z uppercase alphabetic
a...z lowercase alphabetic
0...9 numbers
@ # $ ¢ ? ! . _ special characters

Rules for valid REXX variables are:

1. The first character cannot be 0 through 9 or a period (.)
2. The variable name cannot exceed 250 bytes
3. The variable name should not be RC, SIGL, or RESULT, which are REXX special variables

Compound Variables OR Arrays OR STEMs

Compound variables are a way to create a one or multi dimensional array or a list of variables in
REXX. Subscripts do not necessarily have to be numeric.

A compound variable contains at least one period with characters on both sides of it.
The following are examples of compound variables.

ARRAY.5
Array.Row.Col
employee.name.phone

The first variable in a compound variable always remains a symbol with no substitution. The remaining variables in a compound variable take on values previously assigned. If no value was previously assigned, the variable takes on the uppercase value of the variable name.

This means that if Row = 1 and Col = 2 then,
Array.Row.Col will mean Array.1.2 and if value assigned to this is '123' then,
Array.1.2 = '123'

However, if no value is assigned to this, then
Array.1.2 = 'Array.1.2'

This applies to single and multi-dimensional arrays.

You can initialize an array through this simple method,

Array. = 'Initial value'

This will make all the elements of this array take on the value 'Initial value'. This means,
Array.1.1 = 'Initial value'
Array.1.2 = 'Initial value'
Array.n.n = 'Initial value'

Concatenation Operators

To combine two items into one item, concatenation operator is used.


blank:

Concatenate terms and place one blank in between. Terms that are separated by more than one blank default to one blank when read. For example:
SAY true blue /* result is TRUE BLUE */

|| :
Concatenate terms and place no blanks in between. For example:
(8 / 2)||(3 * 3) /* result is 49 */

abuttal:

Concatenate terms and place no blanks in between. For example:
per_cent'%' /* if per_cent = 5o, result is 5o% */

Data Types

REXX being a free format language, there are no fixed data types that need to be declared before a variable can use a particular data type. A data value can be assigned directly to a variable and can be changed as required.

Eg. You can use the following assignment

Variable1 = 100

without Variable1 being defined/declared as of numeric data type.

In the next instruction the same variable can be assigned a Alphanumeric value.

Variable1 = ‘NUMBER100’

For the internal processing purpose a value is classified as any of the following data types.

A - Alphanumeric
N - Numeric
W - Whole number
L - Lowercase
U - Uppercase
M - Mixed case



© Paras Doshi, 2009.
Page copy protected against web site content infringement by Copyscape