Kilowatt Software's
Classic Rexx Tutorial
Language Level 4.00 (TRL-2)

1 Program structure

A Rexx program consists of one or more procedures. There are three types of procedures.

The following diagrams show variations of these procedure types.

Main.rex, Main2.rex, and Main3.rex are main programs.

The Main2.rex source file includes an internal procedure named: A.

The Main3.rex program invokes an external procedure named: EXT.

Insight!

When you study the above diagram you might believe that a Rexx program consists of a main program, and optionally a series of internal procedures. This is the approach that is used by the majority of programming languages. There are additional flow possibilities within a Rexx program. All of the labels within the source file are eligible targets for the signal instruction (an analogue of a goto), even if these labels are beyond an internal procedure. Note, labels that are followed by a procedure instruction should not be used as targets of a signal instruction.
  


1.1 Main procedure

A simple Rexx program consists of a main procedure only. All of the instructions within the program's source file are included in the main procedure.

As brief as the above program appears, it is actually a full function calculator! It can perform arithmetic computations and string processing requests. The power of this program is due to the INTERPRET instruction.

1.2 Internal procedure

A more complicated Rexx program has a main procedure, but uses an internal procedure as well. The main procedure is concluded by a RETURN or EXIT instruction. The internal procedure is invoked by a CALL instruction, or by a function request. The internal procedure begins with an optional PROCEDURE instruction. The internal procedure is normally concluded by a RETURN instruction. When the procedure is invoked as a function, the RETURN instruction must provide a result. When the procedure is invoked by a CALL instruction the result of the RETURN instruction is available in the RESULT special variable.

Internal procedures can CALL or invoke other procedures as functions. These other procedures can be either internal or external.

The following is an example of a main program that uses an internal procedure.

If an EXIT instruction is executed in an internal procedure, then the main program is concluded as well!

1.3 External procedure

An external procedure is similar to a combination of a main procedure and an internal procedure. An external procedure is stored as a separate source file. Unlike an internal procedure, an external procedure does not begin with a PROCEDURE instruction. Thus it begins with a series of instructions similar to a main procedure. The external procedure is invoked using the same syntax as an internal procedure. The external procedure is normally concluded by a RETURN or EXIT instruction. When the procedure is invoked as a function, the RETURN or EXIT instruction must provide a result. When the procedure is invoked by a CALL instruction the result of the procedure is available in the RESULT special variable.

The external procedure can invoke procedures that are internal to its source file. The external procedure can invoke other external procedures.

If an EXIT instruction is executed in any procedure within the context of an external procedure, then control is returned to the procedure that invoked the external procedure.

The method that is used to locate and activate an external procedure is implementation-dependent.

Note: Some implementations allow external procedures to be written in other programming languages.

The external procedure, factorial.rex, is defined in a separate source file !

1.4 Processing state information is SAVED during function and subroutine calls

The processing state of the following information is saved when a function or subroutine call is performed. The state of this information is restored when the function or subroutine returns.


Kilowatt Software now offers roo!(TM) --an object-oriented Rexx interpreter.

Kilowatt Software's -- Classic Rexx Tutorial -- Back to top

Click here if you have any comments or questions regarding this tutorial

Last updated on: 16 Apr 2003