What is REXX?

The REstructured eXtended eXecutor language is an integral part of the OS/2 operating system.

Basic structure

REXX is:

REXX programs must begin with a comment.

The REXX source code is simple ASCII text prepared with a text editor

Included with OS/2 are the E.EXE and EPM.EXE editors.

REXX Program Names

REXX programs must use the file extension CMD.

Executing REXX programs

There are three methods of running your program:

  1. Type the program name at an OS/2 command prompt.
  2. Single REXX statements may be executed via the REXXTRY facility.
  3. Specify your program as the arguement to PMREXX.

We will not cover them here but OS/2 REXX supports debugging options. Look-up TRACE and the REXX environment variable RXTRACE. Note that PMREXX supports TRACE.

Statement Syntax

Comment


/* This is a comment */

Literal Strings


"Word"
'Multi word phrase'
"Joe's Bar"
'Isn''t this strange?'

Label


HERE:

Numbers:


45
-10.1
5.0E-1

Simple output to the console


SAY 'Simon says: "Type this"'

Simple Variables

Variable names use the symbols:

a-z, A-Z, 0-9, !, ?, _

Variable names cannot begin with a number.

Aa
A_B?why
ALPHAOK?
ALPHA2free.1a
alphafree.1
Alphamulti_segment_ed
aLPha

Note that REXX is not case sensitive, all of the "ALPHA" forms are the same variable.

Complex Variables

Complex Variables

Names.I
Names.2
Names.First
Names.Last

Note that Complex Variables are not arrays.

The variable name, the "STEM", ends at the first period.

Everything after the first period is the "TAIL". The TAIL can take on any value.

Operators

+ - \<plus, minus, not
**raise to a power
* / // %multiply, divide, remainder, integer divide
+ -add, subtract
||concatenate (abuttal)
= \= > < \< \> >= <= <> ><normal comparison
== \== >> << \>> << >>= <<= strict comparison
& | &&and, or, exclusive or

Statements

/* Simple Statements */

A = 3

B = "Three"

c = 3 + 4.5

d = "String" || "s"



SAY A+5 B C

          -->8 Three 7.5

SAY A || B || C

          -->3Three7.5

SAY A || ";" || B

          -->3;Three

SAY A || ";" B

          -->3; Three

SAY D
          -->Strings

There is a difference between concatenate (||) and abut

Slightly more complex statements:

C = ( A + B ) ** 2
i = 2
Lookup.1 = "First"
Lookup.2 = "Second"
Lookup.3 = "Third"
Lookup.4 = "Fourth"
Lookup.5 = "Fifth"
SAY Lookup.i + 3

(By convention Lookup.0 would contain 5, indicating how many items have been defined for the stem "Lookup" Note that this only a convention, not an automatic REXX system feature.)

The following code snip, using complex variables, is valid:

name = "John Smith"
address.name = "123 Elm Street"
name = "Joe Smith"
address.name = "45 Main Street"

Function Call


test = function_name( [expression] [, [expression]] )
call function_name [expression] [, [expression]]

Conditional Statements

/* Conditional Statements */

IF ( A = B ) THEN SAY 'Equal'
ELSE SAY "unequal"

IF ( A = B) THEN DO

         SAY "equal"
         .
         .
         .
         END

ELSE DO

         SAY "unequal"
         .
         .
         .
         END

SELECT
         WHEN ( x = 1 ) THEN SAY "x is one"
         WHEN ( x = 2 ) THEN SAY "x is two"
         WHEN ( x = 3 ) THEN SAY "x is" x
         OTHERWISE SAY "Why did you enter" x || "?"
END

Loops

/* Loops */

DO I=1 TO 6 BY 1

         Y = Y + 1

         END I

DO I=1 TO 7 WHILE ( X < 10 )

         x = X + 1

         END /* I */

DO 10
        x = x + 1
        END

DO FOREVER
        x = x + 1
        IF ( x > 10 ) THEN LEAVE
        END


Rexx Group Charter
Lesson 1 | Lesson 2 | Lesson 3 | Lesson 4
Exercises 1 | Exercises 2 | Exercises 3
Answers to exercises
Exercises 1
Example code
Stock Market | Stock Market_a


About these pages
Content updated: 07-09-2005 08:12am

Page building by: PPWizard Content updated
07-09-2005 08:12am
Valid HTML 4.01!Valid CSS!