REXX

REXX

Infobox programming language
name = REXX

paradigm = multiparadigm: object-oriented, procedural, structured
year = 1979
designer = Mike Cowlishaw
developer = Mike Cowlishaw & IBM
latest release version = ANSI X3.274
latest release date = 1996
typing = dynamic, everything is a string (ClassicREXX) or object (ObjectRexx)
implementations = [http://www2.hursley.ibm.com/netrexx IBM NetREXX] , [http://www.oorexx.org Open Object Rexx] , [http://regina-rexx.sourceforge.net Regina] , others
dialects = Object Rexx, Open Object Rexx, NetRexx
influenced_by = PL/I, EXEC 2, BASIC

REXX (REstructured eXtended eXecutor) is an interpreted programming language which was developed at IBM. It is a structured high-level programming language which was designed to be both easy to learn and easy to read. Both commercial and open source interpreters for REXX are available on a wide range of computing platforms, and compilers are available for IBM mainframes.

Features

REXX has the following characteristics and features:

* character string basis
* dynamic data typing (no declarations)
* no reserved keywords (except in local context)
* arbitrary numerical precision
* decimal arithmetic (floating-point)
* a rich selection of built-in functions (especially string and word processing)
* automatic storage management
* crash protection
* associative arrays
* straightforward access to system commands and facilities
* simple error-handling, and built-in tracing and debugger
* few artificial limitations
* simplified I/O facilities.

REXX has just twenty-three, largely self-evident, instructions ("e.g.", call, parse, and select) with minimal punctuation and formatting requirements. It is essentially an almost free-form language with only one data-type, the character string; this philosophy means that all data are visible (symbolic) and debugging and tracing are simplified.

REXX syntax looks similar to PL/I, but has fewer notations; this makes it harder to parse (by program) but easier to use.

History

REXX was designed and first implemented, in assembly language, as an ‘own-time’ project between 20 March 1979 and mid-1982 by Mike Cowlishaw of IBM, originally as a scripting programming language to replace the languages EXEC and EXEC 2 [cite web|url=http://www-306.ibm.com/software/awdtools/rexx/library/rexxhist.html|title=IBM REXX Brief History|last=Cowlishaw|first=Mike|publisher=IBM|authorlink=Mike Cowlishaw|accessdate=2006-08-15] . It was designed to be a macro or scripting language for any system. As such, REXX is considered a precursor to Tcl and Python.

It was first described in public at the SHARE 56 conference in Houston, Texas, in 1981 [cite web|url=http://www-306.ibm.com/software/awdtools/rexx/library/share56.html|title=REX -- A Command Programming Language|date=1981-02-18|last=Cowlishaw|first=Mike|publisher=SHARE|authorlink=Mike Cowlishaw|accessdate=2006-08-15] , where customer reaction, championed by Ted Johnston of SLAC, led to it being shipped as an IBM product in 1982.

Over the years IBM included REXX in almost all of its operating systems (VM/CMS, VM/GCS, MVS TSO/E, AS/400, VSE/ESA, AIX, CICS/ESA, PC-DOS, and OS/2), and has made versions available for Novell NetWare, Windows, Java, and Linux.

The first non-IBM version was written for PC-DOS by Charles Daney in 1984/5. Other versions have also been developed for Atari, Amiga, Unix (many variants), Solaris, DEC, Windows, Windows CE, PocketPC, MS-DOS, Palm OS, QNX, OS/2, Linux, BeOS, EPOC32, AtheOS, OpenVMS, OpenEdition, Macintosh, and Mac OS X. [cite web|url=http://www.rexxla.org/About_Rexx/mfc/rexxplat.html|title=Rexx Implementations|publisher=RexxLA|accessdate=2006-08-15]

The Amiga version of REXX, called ARexx was included with AmigaOS 2 onwards and was popular for scripting as well as application control. Many Amiga applications have an "ARexx port" built into them which allows control of the application from Rexx. One single Rexx script could even switch between different Rexx ports in order to control several running applications.

Several freeware versions of REXX are available. In 1992, the two most widely-used open-source ports appeared: Ian Collier's REXX/imc for Unix and Anders Christensen's Regina (later adopted by Mark Hessling) for Windows and Linux. BREXX is well-known for WinCE and PocketPC platforms.

In 1996 ANSI published a standard for REXX:ANSI X3.274–1996 “Information Technology – Programming Language REXX”. More than two dozen books on REXX have been published since 1985.

Since the mid-1990s, two newer variants of REXX have appeared:

*NetRexx — which compiles to Java byte-code via Java source code; this has no reserved keywords at all, and uses the Java object model, and is therefore not generally upwards-compatible with ‘classic’ REXX.
*Object REXX — which is an object-oriented generally upwards-compatible version of REXX.

In 1990, Cathy Dager of SLAC organized the first independent REXX symposium, which led to the forming of the REXX Language Association. Symposia are held annually.

REXX marked its 25th anniversary on 20 March 2004, which was celebrated at the REXX Language Association’s 15th International REXX Symposium in Böblingen, Germany, in May 2004.

On October 12, 2004, IBM announced their plan to release their Object REXX implementation under the Common Public License.

On February 22, 2005, the first public release of Open Object Rexx (ooRexx) was announced.

Spelling

Originally it was just called "Rex", "A Reformed EXecutor"; the extra "X" was added to avoid collisions with other products' names. The expansion of Rexx to the REstructured EXtended EXecutor is believed to be a backronym, lacking word from the folks who added the extra X.

REX was originally all uppercase because the mainframe code was uppercase oriented. The "style" in those days was to have all-caps names (partly because almost all code was still all-caps then). For the product it became REXX, and both editions of Mike Cowlishaw's book use all-caps. By the 1990s, though, that was starting to look a bit dated (fine in monospace, but too big/wide in most other fonts) -- most new things had mixed-case names — so Mike started to use Rexx, or small caps EXX if available (REXX -- but with even smaller small-caps). ANSI also liked that (small caps) which preserves the 'all-caps' history, without it seeming to 'shout' from the page.

These days (2008), in plain text, Mike Cowlishaw seems to prefer Rexx, whereas IBM documents and the majority of the web use REXX. The ANSI standard uses the form preferred by the standardization committee, which has small capitals for the final three letters: REXX.

According to Mike, this all-caps style is used on the cover pages of "The REXX Language" TRL. "The NetRexx Language" written by Mike Cowlishaw uses lowercase exx.

Syntax

Looping

The loop control structure in REXX begins with a DO and ends with an END but comes in several varieties. NetRexx uses the keyword LOOP instead of DO for looping, while ooRexx treats LOOP and DO as equivalent when looping.

Traditional forms: do until [condition] [instructions] end

do while [condition] [instructions] end

With an index variable: do "i" = "x" [to "y" ] [by "z"] [instructions] end

The step increment ("z" above) may be omitted and defaults to 1. The upper limit ("y" above) can also be omitted, which makes the loop continue forever. You can also loop forever without an index variable with this: do forever [instructions] end

A program can break out of the current loop with the leave instruction (which is the normal way to exit a "forever" loop), or can short-circuit it with the iterate instruction. The do while and do until forms are equivalent to: do forever if [condition] then leave [instructions] end and: do forever [instructions] if [condition] then leave 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, like many other constructs derived from PL/I: select when [condition] then [instruction] when [condition] then do [instructions] end otherwise [instructions] or NOP end

NOP indicates no instruction is to be executed.

Simple variables

Variables in REXX are typeless, and initially are evaluated as their names, in upper case. Thus a variable's "type" can vary with its use in the program:

say hello /* => HELLO */ hello = 25 say hello /* => 25 */ hello = "say 5 + 3" say hello /* => say 5 + 3 */ interpret hello /* => 8 */ drop hello say hello /* => HELLO */

Compound variables

Unlike many other programming languages, classic REXX has no direct support for arrays of variables addressed by a numerical index. Instead it provides compound variables. A compound variable consists of a stem followed by a tail. A . (dot) is used to join the stem to the tail. If the tails used are numeric, it is easy to produce the same effect as an array.

do i = 1 to 10 "stem.i" = 10 - i end

Afterwards the following variables with the following values exist: stem.1 = 9, stem.2 = 8, stem.3 = 7...

Unlike arrays, the index for a stem variable is not required to have an integer value. For example, the following code is valid: i = 'Monday' stem.i = 2

In REXX it is also possible to set a default value for a stem. stem. = 'Unknown' stem.1 = 'USA' stem.44 = 'UK' stem.33 = 'France'

After these assignments the term stem.3 would produce 'Unknown'.

The whole stem can also be erased with the DROP statement. drop stem.

This also has the effect of removing any default value set previously.

By convention (and not as part of the language) the compound stem.0 is often used to keep track of how many items are in a stem, for example a procedure to add a word to a list might be coded like this: add_word: procedure expose dictionary. parse arg w n = dictionary.0 + 1 dictionary.n = w dictionary.0 = n return

It is also possible to have multiple elements in the tail of a compound variable. For example: m = 'July' d = 15 y = 2005 day.y.m.d = 'Friday'

Multiple numerical tail elements can be used to provide the effect of a multi-dimensional array.

Features similar to REXX compound variables are found in many other languages ("associative arrays" in AWK, "hashes" in Perl, "Hashtables" in Java, "etc"). Most of these languages provide an instruction to iterate over all the keys (or "tails" in REXX terms) of such a construct, but this is lacking in classic REXX. Instead it is necessary to keep auxiliary lists of tail values as appropriate. For example in a program to count words the following procedure might be used to record each occurrence of a word. add_word: procedure expose count. word_list parse arg w . count.w = count.w + 1 /* assume count. has been set to 0 */ if count.w = 1 then word_list = word_list w return

and then later do i = 1 to words(word_list) w = word(word_list,i) say w count.w end

At the cost of some opacity it is possible to combine these techniques into a single stem. add_word: procedure expose dictionary. parse arg w . dictionary.w = dictionary.w + 1 if dictionary.w = 1 /* assume dictionary. = 0 */ then do n = dictionary.0+1 dictionary.n = w dictionary.0 = n end returnand later do i = 1 to dictionary.0 w = dictionary.i say i w dictionary.w endHowever, REXX provides no safety net here, so if one of your words happens to be a whole number less than dictionary.0 the above technique will fail mysteriously.

Recent implementations of REXX, include IBM's Object REXX and the open source implementations like ooRexx include a new language construct to simplify iteration over the value of a stem, or over another collection object such as an array, table, list, etc. do i over stem. say i '-->' stem.i end

Keyword instructions

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 (arguments, at top level tail of command line)
* linein (standard input, e.g. keyboard)
* pull (REXX data queue or standard input)
* source (info on how program was executed)
* value (an expression) with
*: the keyword "with" is required to indicate where the expression ends
* var (a variable)
* version (version/release number)

and "template" can be:
* list of variables
* column number delimiters
* literal delimiters

upper is optional; if 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.

INTERPRET

The INTERPRET instruction is very powerful and one of the two reasons why writing REXX compilers isn't trivial, the other reason being REXX's decimal arbitrary precision arithmetic:

/* a touch of LISP */ X = 'square' interpret 'say' X || '(4) ; exit' SQUARE: return arg(1) * arg(1)

This displays 16 and exits. Because anything in REXX are strings, even rational numbers with exponents, and last but not least complete programs, REXX offers to interpret strings as programs.

This feature was used to implement something like function parameters, e.g. passing SIN, COS, etc. to a procedure SIMPSON to calculate integrals.

Note that REXX offers only basic math functions like ABS, DIGITS, MAX, MIN, SIGN, RANDOM, and a complete set of hex plus binary conversions with bit operations. Anything else like SIN has to be implemented from scratch or using external libraries. The latter typically don't support arbitrary precision.

Later versions (non-classic) support CALL variable constructs. Together with the built-in function VALUE, CALL allows to avoid many cases of INTERPRET. This is a classic program:

/* terminated by input "exit" or similar */ do forever ; interpret linein() ; end

A slightly more sophisticated "REXX calculator":

X = 'input BYE to quit' do until X = 'BYE' ; interpret 'say' X ; pull X ; end

PULL is a shorthand for parse upper pull like ARG for parse upper arg.

NUMERIC

say digits() fuzz() form() /* => 9 0 SCIENTIFIC */ say 999999999 + 1 /* => 1.000000000E+9 */ numeric digits 10 /* only limited by available memory */ say 999999999 + 1 /* => 1000000000 */

say 0.9999999999 = 1 /* => 0 (false) */ numeric fuzz 3 say 0.99999999 = 1 /* => 1 (true) */ say 0.99999999 = 1 /* => 0 (false) */

say 100 * 123456789 /* => 1.23456789E+10 */ numeric form engineering say 100 * 123456789 /* => 12.34567890E+9 */

SIGNAL

The REXX SIGNAL instruction is intended for abnormal changes in the flow of control (see the next section). However, it can be misused and treated like the GOTO statement found in other languages (although it is not strictly equivalent, because it terminates loops and other constructs). This can produce difficult to read code.

Error handling and exceptions

It is possible in REXX to intercept and deal with errors and other exceptions, using the SIGNAL instruction. There are seven system "conditions": ERROR, FAILURE, HALT, NOVALUE, NOTREADY, LOSTDIGITS and SYNTAX. Handling of each can be switched on and off in the source code as desired.

This example will run until stopped by the user: signal on halt; do a = 1 say a do 100000 /* a delay */ end end halt: say "The program was stopped by the user" exit

Virtually all serious REXX programs contain signal on novalue or a similar statement. This disables the "feature", where undefined variables get their own (upper case) name as value. The status of a variable can be checked with the built-in function SYMBOL returning VAR for defined variables.

Function VALUE can be used to get the value of variables without triggering a NOVALUE condition, but its main purpose is to read and set environment variables - similar to POSIX getenv and putenv.

Conditions

When a condition is handled by SIGNAL ON, the SIGL and RC system variables can be analyzed to understand the situation. RC contains the REXX error code and SIGL contains the line number where the error arose.

Beginning with REXX version 4 conditions can get names, and there's also a CALL ON construct. That's handy if external functions do not necessarily exist:

ChangeCodePage: procedure /* protect SIGNAL settings */ signal on syntax name ChangeCodePage.Trap return SysQueryProcessCodePage() ChangeCodePage.Tr
return 1004 /* windows-1252 on OS/2 */

See also

*ARexx - The native REXX interpreter of AmigaOS
*XEDIT - text editor(s) with native REXX support
*Comparison of computer shells
*Comparison of programming languages

References

Books

* Cowlishaw, Michael. "The Rexx Language: A Practical Approach to Programming". Prentice Hall, 1990. ISBN 0-13-780651-5.
* Cowlishaw, Michael. "The NetRexx Language". Prentice Hall, 1997. ISBN 0-13-806332-X.
* Daney, Charles. "Programming in REXX". McGraw-Hill, TX, 1990. ISBN 0-07-015305-1.
* Deuring, Johannes. "REXX Grundlagen für die z/OS Praxis". Germany, 2005. ISBN 3-486-20025-9.
* Ender, Tom. "Object-Oriented Programming With Rexx". John Wiley & Sons, 1997. ISBN 0-471-11844-3.
* Fosdick, Howard. "Rexx Programmer's Reference". Wiley/Wrox, 2005. ISBN 0-7645-7996-7.
* Gargiulo, Gabriel. "REXX with OS/2, TSO, & CMS Features". MVS Training, 1999 (third edition 2004). ISBN 1-892559-03-X.
* Goldberg, Gabriel and Smith, Philip H. "The Rexx Handbook ". McGraw-Hill, TX, 1992. ISBN 0-07-023682-8.
* Goran, Richard K. "REXX Reference Summary Handbook". CFS Nevada, Inc.,1997. ISBN 0-9639854-3-4.
* IBM Redbooks. "Implementing Rexx Support in Sdsf". Vervante, 2007. ISBN 0-738-48914-X.
* Kiesel, Peter C. "Rexx: Advanced Techniques for Programmers". McGraw-Hill, TX, 1992. ISBN 0-07-034600-3.
* O'Hara, Robert P. and Gomberg, David Roos. "Modern Programming Using Rexx". Prentice Hall, 1988. ISBN 0-13-597329-5.
* Rudd, Anthony S. "Practical Usage of Rexx". Ellis Horwood Ltd., 1991. ISBN 0-13682-790-X.
* Schindler, William. "Down to Earth Rexx". Perfect Niche Software, 2000. ISBN 0-9677590-0-5.

External links

* [http://domino.research.ibm.com/comm/research_people.nsf/pages/cowlishaw.index.html Mike Cowlishaw] at IBM
* [http://www.ibm.com/rexx/ REXX language page] at IBM
* [http://www.rexxla.org REXX Language Association]
** [http://www.rexxla.org/About_Rexx/mfc/rexxbook.html RexxLA's list of Rexx books]
* [http://www.RexxInfo.org REXX Information-- Downloads, tools, tutorials, reference materials, etc.]
* [http://www.thescriptlibrary.com/default.asp?Action=Browse&Level=ScriptLanguage&ScriptLanguage=Rexx The Script Library]

Classic interpreters

* [http://regina-rexx.sourceforge.net Regina] : open-source (LGPL) interpreter for Linux, BSD, Windows, "etc."
* [http://users.comlab.ox.ac.uk/ian.collier/Rexx/rexximc.html REXX/imc] : open-source (nonstandard license) interpreter for Unix and Linux systems.
* [http://ftp.gwdg.de/pub/languages/rexx/brexx/html/rx.html BREXX] : open-source (GPL) interpreter for DOS, Linux, Windows CE, "etc."
* [http://www.borg.com/~jglatt/rexx/rexxuser.htm Reginald] : free interpreter for Windows.
* [http://www.kilowattsoftware.com/rooPage.htm roo!] : freeware interpreter for Windows with object-oriented extensions from Kilowatt Software.
* [http://www.kilowattsoftware.com/r4Page.htm r4] : freeware interpreter for Windows from Kilowatt Software.
* [http://www.jaxo.com/rexx REXX for Palm OS] : shareware interpreter for Palm OS from Jaxo Inc.
* [http://www.quercus-sys.com Personal REXX] : commercial interpreter for Windows, OS/2 and DOS from Quercus Systems.
* [http://www.sedit.com/rexxgrph.html S/REXX] : commercial interpreter for UNIX and Windows from Benaroya.
* [http://www.wrkgrp.com/unirexx/index.html uni-REXX] : commercial interpreter for UNIX from The Workstation Group Ltd.

Other interpreters

* [http://www.oorexx.org Open Object Rexx web site]
* [http://www2.hursley.ibm.com/netrexx IBM NetREXX web site]

Compilers

* [http://www.ibm.com/software/awdtools/rexx/rexxzseries/index.html IBM Compiler and Library for REXX on zSeries]

Newsgroups

* [http://groups.google.com/group/comp.lang.rexx comp.lang.rexx]

Tutorials

* [http://www-106.ibm.com/developerworks/library/l-rexx.html Rexx for everyone] : An introduction by David Mertz for IBM developerWorks.
* [http://www.geocities.com/SiliconValley/Garage/3323/aat/index.html Vladimir Zabrodsky's "Album of Algorithms and Techniques for Standard Rexx"]
* [http://www.geocities.com/SiliconValley/Garage/3323/introrexx.html Vladimir Zabrodsky's "An Introduction to the Rexx Programming Language"]
* [http://pleac.sourceforge.net/pleac_rexx/index.html PLEAC-REXX] : Programming Language Examples Alike Cookbook for REXX
* [http://hobbes.nmsu.edu/pub/os2/dev/rexx/rxtt36.zip Tips & tricks] 3.60 by Bernd Schemmer (OS/2 INF format, 755 KB ZIP, 2004)
* [http://www.mindspring.com/~dave_martin/RexxFAQ.html Rexx Frequently Asked Questions (FAQ)]
* [http://www.rexxla.org/About_Rexx/rexxtut.html Introductory Rexx Tutorial - SHARE, Spring 1997]


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • REXX — Saltar a navegación, búsqueda REXX Paradigma: multiparadigma Apareció en: 1979 Diseñado por: Mike Cowlishaw Desarrollador: Mike Cowlishaw e IBM Última versión: ANSI X3.27 …   Wikipedia Español

  • REXX — Erscheinungsjahr: 1979 Entwickler: Mike Cowlishaw Aktuelle Version: ANSI X3.274  (1996) Typisierung: dynamisch …   Deutsch Wikipedia

  • Rexx — (Abk. f. Restructured Extended Executor) ist eine von Mike Cowlishaw bei IBM entwickelte Skriptsprache. Inhaltsverzeichnis 1 Herkunft 2 Grundlegende Konzepte 2.1 Alles ist ein String 2.2 Auswertungslogik …   Deutsch Wikipedia

  • REXX — или Rexx (REstructured eXtended eXecutor, произносится «рекс»)  интерпретируемый язык программирования, разработанный фирмой IBM. Существуют как коммерческие, так и свободно распространяемые реализации данного языка. Пик своего… …   Википедия

  • REXX —   [Abk. für Restructured Extended Executor, dt. »umstrukturierter erweiterter Durchführer«], eine von Mike F. Cowlishaw um 1980 bei IBM entwickelte prozedurale Programmiersprache (prozedurale Sprache), die leicht zu erlernen und einfach zu… …   Universal-Lexikon

  • REXX — (REstructured eXtended eXecutor) es un lenguaje de programación desarrollado en IBM por Michael Cowlishaw del que existen numerosas implementaciones disponibles con código abierto. Es un lenguaje de programación estructurado de alto nivel… …   Enciclopedia Universal

  • REXX — Restructured Extended Executor Restructured Extended Executor (REXX) est un langage, initialement Revised EXecutor, mais le sigle était déjà déposé, a été inventé par Mike Cowlishaw, chercheur d IBM. Langage interprété procédural, il est un des… …   Wikipédia en Français

  • Rexx — Restructured Extended Executor Restructured Extended Executor (REXX) est un langage, initialement Revised EXecutor, mais le sigle était déjà déposé, a été inventé par Mike Cowlishaw, chercheur d IBM. Langage interprété procédural, il est un des… …   Wikipédia en Français

  • REXX — ● sg. np. m. ►LANG REstructured eXtended eXecutor language... attaque! Langage de commande d OS/2. Pour faire un bon Rexx, prendre un shell Unix convenable, et remplacer tous les noms de commandes par des trucs à vous pour dérouter tout le monde …   Dictionnaire d'informatique francophone

  • REXX —    Acronym formed from Restructured Extended Executor Language. A scripting language from IBM, originally written by Mike Cowlishaw of IBM UK in 1979 for the VM mainframe environment and now available on many operating systems, including OS/2,… …   Dictionary of networking

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”