Encyclopedia > REXX programming language

  Article Content

REXX

Redirected from REXX programming language

The REXX (Restructured Extended Executor) programming language was designed and implemented between 1979 and 1982 by Mike Cowlishaw of IBM. It is a modern, structured, high-level programming language that was designed to be both easy to learn and easy to read. This was achieved by implementing the following characteristics and features:

  • character string orientation

  • dynamic data typing (no declarations)

  • automatic storage management

  • crash protection

  • content-addressable data structures

  • straight-forward access to system commands and facilities

  • a rich selection of built-in functions

  • simple error-handling and built-in debugger

  • few artificial limitations

REXX has just twenty-three, largely self-evident keywords (ie, CALL, PARSE, SELECT) and minimial punctuation requirements. It is essentially a free-form language with only one data-type, the character string; users never have to worry about data conversion.

REXX looks a lot like PL/1[?].

Table of contents

History

Originally a scripting language developed at IBM. REXX was the successor to the script languages EXEC and EXEC 2. It was also designed to be a macro or scripting language for any system. As such, it is a precursor to TCL[?] and Python.

Over the years IBM developed versions for many of its operating systems: VM/CMS, OS/2, PC-DOS, MVS/TSO, AS/400, and AIX. Non-IBM versions have also been developed for Atari, Unix, DEC, Windows, and MS-DOS. Later versions of the Amiga OS included a version of REXX called AREXX.

Several freeware versions are available. REXX/IMC and Regina are the most widely-used open-source ports to Windows and Linux.

In 1996 ANSI published a standard for REXX: ANSI X3.274-1996 "Information Technology - Programming Language REXX"

In recent years, two newer variants of REXX have appeared:


Syntax

Looping

The DO control structure always begins with a DO and ends with an END.

DO UNTIL:

    do until [condition]
    [instructions]
    end

DO WHILE:

    do while [condition is true]
    [instructions]
    end

Stepping through a variable:

    do i = x to y by z
    [instructions]
    end

Looping forever until exiting with LEAVE:

    do forever
      if [condition] then leave
    end

Looping a fixed number of times

    do i = x to y by z for a
    [instructions]
    end


Conditionals

Testing conditions with IF

    if [condition] then
      do
      [instructions]
      end
    else
      do
      [instructions]
      end

For single instructions, DO and END can also be omitted:

    if [condition] then
      [instruction]
    else
      [instruction]


Testing for multiple conditions

SELECT is REXX's CASE structure

    select
      when [condition] then
      do
      [instruction]
      end
    otherwise
      do
      [instruction] or NOP
      end

NOP indicates no instruction is to be executed.


PARSE

The PARSE instruction is particularly powerful; it combines some useful string-handling functions. Its syntax is:

    parse [upper] origin template

where origin specifies the source:

  • arg (command line variable)
  • linein (keyboard)
  • pull (REXX data queue)
  • source (OS/2 info on how program was executed)
  • value (a literal or a function)
    • the keyword with required to indicate where the literal ends
  • var (a variable)
  • version (version/release number)

and template can be:

  • list of variables
  • column number delimiters
  • literal delimiters

upper is optional; it you specify it, data will be converted to upper case.

Examples:

Using a list of variables as template

    myVar = "John Smith"
    parse var MyVar firstName lastName
    say "First name is:" firstName
    say "Last name is:"  lastName

displays the following

    First name is: John
    Last name is: Smith

Using a delimiter as template:

    myVar = "Smith, John"
    parse var MyVar LastName "," FirstName
    say "First name is:" firstName
    say "Last name is:"  lastName

also displays the following

    First name is: John
    Last name is: Smith

Using column number delimiters:

    myVar = "(202) 123-1234"
    parse var MyVar 2 AreaCode 5  7 SubNumber
    say "Area code is:" AreaCode
    say "Subscriber number is:" SubNumber

displays the following

    Area code is: 202
    Subscriber number is: 123-1234

A template can use a combination of variables, literal delimiters, and column number delimiters.


Under OS/2

REXX is included in the base operating system of OS/2, and is also used as the macro language in many applications. Under OS/2, a REXX program begins with matched comment delineaters, /* */, to indicate to the OS that it is a REXX program:

    /* sample.cmd */
    say "Hello World"

Instructions between quotes are passed to the OS:

    /* sample.cmd */
    'dir /p /w'


Spelling

Cowlishaw seems to prefer Rexx, whereas IBM sales, ANSI, and the majority of the web uses REXX.


External Links



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Grateful Dead

... -- lengthy instrumental jams with guitar solos by Garcia, best exemplified by "Dark Star" -- but lacked the energy of the shows and did not sell terribly well. The 1970s ...

 
 
 
This page was created in 35.5 ms