Program Structure


A NetRexx program permits the definition of multiple classes and methods, and also permits the writing of 'low boilerplate' programs by providing a default class and method as appropriate. The simplest documented NetRexx program might therefore be:

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

More generally, a NetRexx program consists of:

  1. An optional prologue (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. Zero or more property variable assignments (which may just set the type of each variable), along with optional PROPERTIES instructions that can alter their attributes, and optional NUMERIC instructions.
  2. Zero or more method definitions, each introduced by a METHOD instruction.

Methods may contain any instructions, except the CLASS, METHOD, and PROPERTIES instructions and those allowed in the prologue.

For example:

  /* A program with two classes */
  import java.applet.    -- for example

class testclass extends Applet i=int -- property (instance) variable j=int 3 -- this one is initialized to 3

method start say 'I started'

method stop say 'I stopped'

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'

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 following defaults are provided:

  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 the name derived from that of the source file) and a default METHOD instruction (with a name and attributes appropriate for the environment, such as 'main') is inserted. In this 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 Java environment, the 'main' method in a stand-alone application is passed the words forming the command string as a String array. When NetRexx provides the method instruction by default, it also constructs a Rexx string 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 an RETURN instruction is added unless a value is expected for a method, in which case an error is reported.

Language processors may provide option(s) to prevent, or warn of, these defaults being applied, as desired.


[ previous section | contents]

From 'netrexx.doc', version 0.75.
Copyright(c) IBM Corporation, 1996. All rights reserved. ©