Skip to main content

Software > Software Development > IBM REXX Family >

NetRexx

Technical detail

Program structure

A NetRexx program is a collection of clauses derived from a single implementation-defined source stream (such as a file). When a program is processed by a language processor[1]  it defines one or more classes. Classes are usually introduced by the class instruction, but if the first is a standard class, intended to be run as a stand-alone application, then the class instruction can be omitted. In this case, NetRexx defines an implied class and initialization method that will be used.

The implied class and method permits the writing of 'low boilerplate' programs, with a minimum of syntax. The simplest, documented, NetRexx program that has an effect might therefore be:

Example:

  /* This is a very simple NetRexx program */
say 'Hello World!'

In more detail, a NetRexx program consists of:

  1. An optional prolog (package, import, and options instructions). Only one package instruction is permitted per program.
  2. One or more class definitions, each introduced by a class instruction.

A class definition comprises:

  1. The class instruction which introduces the class (which may be inferred, see below).
  2. Zero or more property variable assignments, along with optional properties instructions that can alter their attributes, and optional numeric and trace instructions. Property variable assignments take the form of an assignment, with an optional '=' and expression, which may:
    • just name a property (by omitting the '=' and expression of the assignment), in which case it refers to a string of type Rexx
    • assign a type to the property (when the expression evaluates to just a type)
    • assign a type and initial value to the property (when the expression returns a value).
  3. Zero or more method definitions, each introduced by a method instruction (which may be inferred if the class instruction is inferred, see below).

A method definition comprises:

  • Any NetRexx instructions, except the class, method, and properties instructions and those allowed in the prolog (the package, import, and options instructions).

Example:

  /* A program with two classes */
import java.applet. -- for example
  class testclass extends Applet
properties public
state -- property of type 'Rexx'
i=int -- property of type 'int'
properties constant
j=int 3 -- property initialized to '3'
    method start
say 'I started'
state='start'
    method stop
say 'I stopped'
state='stop'
  class anotherclass
method testing
loop i=1 to 10
say '1, 2, 3, 4...'
if i=7 then return
end
return
    method anothertest
say '1, 2, 3, 4'

This example shows a prolog (with just an import instruction) followed by two classes. The first class includes two public properties, one constant property, and two methods. The second class includes no properties, but also has two methods.

Note that a return instruction implies no static scoping; the content of a method is ended by a method (or class) instruction, or by the end of the source stream. The return instruction at the end of the testing method is, therefore, unnecessary.

Program defaults

The following defaults are provided for NetRexx programs:

  1. If, while parsing prolog instructions, some instruction that is not valid for the prolog and is not a class instruction is encountered, then a default class instruction (with an implementation-provided short name, typically derived from the name of the source stream) is inserted. If the instruction was not a method instruction, then a default method instruction (with a name and attributes appropriate for the environment, such as main) is also inserted.
    In this latter case, it is assumed that execution of the program will begin by invocation of the default method. In other words, a 'stand-alone' application can be written without explicitly providing the class and method instructions for the first method to be executed.
    In the reference implementation, the main method in a stand-alone application is passed the words forming the command string as an array of strings of type java.lang.String (one word to each element of the array). When the NetRexx reference implementation provides the main method instruction by default, it also constructs a NetRexx string of type Rexx from this array of words, with a blank added between words, and assigns the string to the variable arg.
    The command string may also have been edited by the underlying operating system environment; certain characters may not be allowed, multiple blanks or whitespace may have been reduced to single blanks, etc.
  2. If a method ends and the last instruction at the outer level of the method scope is not return then a return instruction is added if it could be reached. In this case, if a value is expected to be returned by the method (due to other return instructions returning values, or there being a returns keyword on the method instruction), an error is reported.

Language processors may provide options to prevent, or warn of, these defaults being applied, as desired.

Footnotes:

[1]  Such as a compiler or interpreter.

 

 

PreviousTable of contents Next
We're here to help
Easy ways to get the answers you need.
E-mail us

or call us at
877-426-3774
Priority code:
104CBW67