”;
Rexx – Overview
Rexx (Restructured Extended Executor) is designed to be a scripting language. Its goal is to make scripting as easy, fast, reliable, and error-free as possible. Many programming languages are designed for compatibility with older languages, and are written for specific audiences or platforms. Rexx ignores extraneous objectives. It was designed from day one to be powerful, yet easy to use.
Rexx was designed and first implemented, in assembly language, as an ”own-time” project between 20th March 1979 and the middle of 1982 by Mike Cowlishaw of IBM, originally as a scripting programming language to replace the languages EXEC and EXEC 2. It was designed to be a macro or scripting language for any system. As such, Rexx is considered a precursor to Tcl and Python. Rexx was also intended by its creator to be a simplified and easier to learn version of the PL/I programming language.
Features of Rexx
Rexx as a programming language has the following key features −
-
Simple syntax
-
The ability to route commands to multiple environments
-
The ability to support functions, procedures and commands associated with a specific invoking environment.
-
A built-in stack, with the ability to interoperate with the host stack if there is one.
-
Small instruction set containing just two dozen instructions
-
Freeform syntax
-
Case-insensitive tokens, including variable names
-
Character string basis
-
Dynamic data typing, no declarations
-
No reserved keywords, except in local context
-
No include file facilities
-
Arbitrary numerical precision
-
Decimal arithmetic, floating-point
-
A rich selection of built-in functions, especially string and word processing
-
Automatic storage management
-
Crash protection
-
Content addressable data structures
-
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
The official website for Rexx is www.oorexx.org
Rexx – Environment
Before you can start working on Rexx, you need to ensure that you have a fully functional version of Rexx running on your system. This chapter will explain the installation of Rexx and its subsequent configuration on a Windows machine to get started with Rexx.
Ensure the following System requirements are met before proceeding with the installation.
System Requirements
Memory | 2 GB RAM (recommended) |
Disk Space | No minimum requirement. Preferably to have enough storage to store the programs which will be created using Rexx. |
Operating System Version | Rexx can be installed on Windows, Ubuntu/Debian, Mac OS X. |
Downloading Rexx
To download Rexx, you should use the following URL − https://www.oorexx.org/download.html
This page has a variety of downloads for various versions of Rexx as shown in the following screenshot.
Click on the ‘ooRexx install files’ in the table with the header of Release 4.2.0.
After this, you will be re-directed to the following page.
Click on the ooRexx-4.2.0.windows.x86_64.exe to download the 64-bit version of the software. We will discuss regarding the installation of the software in the following chapter.
Rexx – Installation
The following steps will explain in detail how Rexx can be installed on a Windows system.
Step 1 − Launch the Installer downloaded in the earlier section. After the installer starts, click on the Run button.
Step 2 − Click the next button on the following screen to proceed with the installation.
Step 3 − Click on the I Agree button to proceed.
Step 4 − Accept the default components and then click on the next button.
Step 5 − Choose the installation location and click on the Next button.
Step 6 − Accept the default processes which will be installed and click on the Next button.
Step 7 − Choose the default file associations and click on the Next button.
Step 8 − Click on the check boxes of send Rexx items to the executables and then click on the Next button as shown in the following screenshot.
Step 9 − In the next screen, choose the editor for working with Rexx files. Keep the notepad as the default option. Also accept the default extension for each Rexx file.
Step 10 − Accept the default settings on the following screen that comes up and click on the Next button to proceed further with the installation.
Step 11 − Finally click on the Install button to proceed with the installation.
Step 12 − Once the installation is complete, you need to click on the Next button to proceed further.
Step 13 − Click on the Finish button to complete the installation.
Rexx – Installation of Plugin-Ins
In this chapter, we will discuss on how to install plug-ins on popular IDE’s (Integrated Development Environment). Rexx as a programming language is also available in popular IDE’s such as Eclipse. Let’s look at how we can get the required plugin’s in these IDE’s, so that you have more choices in working with Rexx.
Installation in Eclipse
To make a trouble-free installation of Rexx in Eclipse, you will need to adhere to the following steps.
Step 1 − Open Eclipse and click on the Menu item, Help → Eclipse Marketplace as shown in the following screenshot.
Step 2 − In the next dialog box, enter Rexx in the search criteria and click on the search button.
Once done, click the Install button.
Step 3 − Click on the Confirm button to further continue with the features installation.
Step 4 − Eclipse will then download the necessary files to start off with the installation. Once done, Eclipse will ask for accepting the license agreements. Click on accepting the license agreements and then click on the Finish button as shown in the following screenshot.
Eclipse will then start installing the software in the background.
Step 5 − You will probably get a security warning (as shown in the following screenshot). Click on the OK button to proceed.
Step 6 − You will be prompted to restart Eclipse once the updates are installed. Click Yes to restart Eclipse.
Rexx – Basic Syntax
In order to understand the basic syntax of Rexx, let us first look at a simple Hello World program.
Example
/* Main program */ say "Hello World"
One can see how simple the hello world program is. It is a simple script line which is used to execute the Hello World program.
The following things need to be noted about the above program −
-
The say command is used to output a value to the console.
-
The /* */ is used for comments in Rexx.
The output of the above program will be −
Hello World
General Form of a Statement
In Rexx, let’s see a general form of a program. Take a look at the following example.
/* Main program */ say add(5,6) exit add: parse arg a,b return a + b
The output of the above program will be −
11
Let’s go through what we have understood from the above program −
-
Add is a function defined to add 2 numbers.
-
In the main program, the values of 5 and 6 is used as parameters to the add function.
-
The exit keyword is used to exit from the main program. This is used to differentiate the main program from the add function.
-
The add function is differentiated with the ‘:’ symbol.
-
The parse statement is used to parse the incoming arguments.
-
Finally, the return statement is used to return the sum of the numeric values.
Subroutines and Functions
In Rexx, the code is normally divided into subroutines and functions. Subroutines and functions are used to differentiate the code into different logical units. The key difference between subroutines and functions is that functions return a value whereas subroutines don’t.
Below is a key difference example between a subroutine and a function for an addition implementation −
Function Implementation
/* Main program */ say add(5,6) exit add: parse arg a,b return a + b
Subroutine Implementation
/* Main program */ add(5,6) exit add: parse arg a,b say a + b
The output of both the programs will be the value 11.
Executing Commands
Rexx can be used as a control language for a variety of command-based systems. The way that Rexx executes commands in these systems is as follows. When Rexx encounters a program line which is neither an instruction nor an assignment, it treats that line as a string expression which is to be evaluated and then passed to the environment.
An example is as follows −
Example
/* Main program */ parse arg command command "file1" command "file2" command "file3" exit
Each of the three similar lines in this program is a string expression which adds the name of a file (contained in the string constants) to the name of a command (given as a parameter). The resulting string is passed to the environment to be executed as a command. When the command has finished, the variable “rc” is set to the exit code of the command.
The output of the above program is as follows −
sh: file1: command not found 3 *-* command "file1" >>> " file1" +++ "RC(127)" sh: file2: command not found 4 *-* command "file2" >>> " file2" +++ "RC(127)" sh: file3: command not found 5 *-* command "file3" >>> " file3" +++ "RC(127)"
Keywords in Rexx
The free syntax of REXX implies that some symbols are reserved for the language processor”s use in certain contexts.
Within particular instructions, some symbols may be reserved to separate the parts of the instruction. These symbols are referred to as keywords. Examples of REXX keywords are the WHILE in a DO instruction, and the THEN (which acts as a clause terminator in this case) following an IF or WHEN clause.
Apart from these cases, only simple symbols that are the first token in a clause and that are not followed by an “=” or “:” are checked to see if they are instruction keywords. You can use the symbols freely elsewhere in clauses without their being taken to be keywords.
Comments in Rexx
Comments are used to document your code. Single line comments are identified by using the /* */ at any position in the line.
An example is as follows −
/* Main program */ /* Call the add function */ add(5,6) /* Exit the main program */ exit add: /* Parse the arguments passed to the add function */ parse arg a,b /* Display the added numeric values */ say a + b
Comments can also be written in between a code line as shown in the following program −
/* Main program */ /* Call the add function */ add(5,6) /* Exit the main program */ exit add: parse /* Parse the arguments passed to the add function */ arg a,b /* Display the added numeric values */ say a + b
The output of the above program will be −
11
You can also have multiple lines in a comment as shown in the following program −
/* Main program The below program is used to add numbers Call the add function */ add(5,6) exit add: parse arg a,b say a + b
The output of the above program will be −
11
Rexx – DataTypes
In any programming language, you need to use various variables to store various types of information. Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory to store the value associated with that variable.
You may like to store information of various data types like String, Character, Wide Character, Integer, Floating Point, Boolean, etc. Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory.
Built-in Data Types
Rexx offers a wide variety of built-in data types. Following is a list of data types which are defined in Rexx.
-
Integer − A string of numerics that does not contain a decimal point or exponent identifier. The first character can be a plus (+) or minus (-) sign. The number that is represented must be between -2147483648 and 2147483647, inclusive.
-
Big Integer − A string of numbers that does not contain a decimal point or an exponent identifier. The first character can be a plus (+) or minus (-) sign. The number that is represented must be between -9223372036854775808 and 2147483648, inclusive, or between 2147483648 and 9223372036854775807.
-
Decimal − It will be from one of the following formats −
-
A string of numerics that contains a decimal point but no exponent identifier. The p represents the precision and s represents the scale of the decimal number that the string represents. The first character can be a plus (+) or minus (-) sign.
-
A string of numerics that does not contain a decimal point or an exponent identifier. The first character can be a plus (+) or minus (-) sign. The number that is represented is less than -9223372036854775808 or greater than 9223372036854775807.
-
-
Float − A string that represents a number in scientific notation. The string consists of a series of numerics followed by an exponent identifier (an E or e followed by an optional plus (+) or minus (-) sign and a series of numerics). The string can begin with a plus (+) or minus (-) sign.
-
String − A normal string of characters.
Following are some examples of how each data type can be used. Again each data type will be discussed in detail in the subsequent chapters. This is just to get you up to speed with a brief description of the above mentioned data types.
Integer
An example of how the number data type can be used is shown in the following program. This program shows the addition of 2 Integers.
Example
/* Main program The below program is used to add numbers Call the add function */ add(5,6) exit add: parse arg a,b say a + b
The output of the above program will be −
11
Big Integer
The following program shows the capability of Rexx to handle big integers. This program shows how to add 2 big integers.
Example
/* Main program The below program is used to add numbers Call the add function */ add(500000000000,6000000000000000000000) exit add: parse arg a,b say a + b
The output of the above program will be −
6.00000000E+21
Decimal
The following program shows the capability of Rexx to handle decimal numbers. This program shows how to add 2 decimal numbers.
Example
/* Main program The below program is used to add numbers Call the add function */ add(5.5,6.6) exit add: parse arg a,b say a + b
The output of the above program will be −
12.1
Float
The following example show cases how a number can work as a float.
Example
/* Main program The below program is used to add numbers Call the add function */ add(12E2,14E4) exit add: parse arg a,b say a + b
The output of the above program will be −
141200
String
An example of how the Tuple data type can be used is shown in the following program.
Here we are defining a Tuple P which has 3 terms. The tuple_size is an inbuilt function defined in Rexx which can be used to determine the size of the tuple.
Example
/* Main program */ display("hello") exit display: parse arg a say a
The output of the above program will be −
hello
Rexx – Variables
In Rexx, all variables are bound with the ‘=’ statement. Variable names are sometimes referred to as symbols. They may be composed of Letters, Digits, and Characters such as ‘. ! ? _’. A variable name you create must not begin with a digit or a period. A simple variable name does not include a period. A variable name that includes a period is called a compound variable and represents an array or table.
The following are the basic types of variables in Rexx which were also explained in the previous chapter −
-
Integers − This is used to represent an integer or a float. An example for this is 10.
-
Big integers − This represents a large integer value.
-
Decimal − A decimal value is a string of numerics that contains a decimal point but no exponent identifier.
-
Float − A float value is a string that represents a number in the scientific notation.
-
String − A series of characters defines a string in Rexx.
Different Types of Variable Functions
In this section, we will discuss regarding the various functions a variable can perform.
Variable Declarations
The general syntax of defining a variable is shown as follows −
var-name = var-value
where
-
var-name − This is the name of the variable.
-
var-value − This is the value bound to the variable.
The following program is an example of the variable declaration −
Example
/* Main program */ X = 40 Y = 50 Result = X + Y say Result
In the above example, we have 2 variables, one is X which is bound to the value 40 and the next is Y which is bound to the value of 50. Another variable called Result is bound to the addition of X and Y.
The output of the above program will be as follows −
90
Naming Variables
Variable names are sometimes referred to as symbols. They may be composed of Letters, Digits, and Characters such as ‘. ! ? _’ . A variable name you create must not begin with a digit or period.
If a variable has not yet been assigned a value, it is referred to as uninitialized. The value of an uninitialized variable is the name of the variable itself in uppercase letters.
An example of an unassigned variable is as follows −
Example
/* Main program */ unassignedvalue say unassignedvalue
If you run the above program you will get the following output −
UNASSIGNEDVALUE sh: UNASSIGNEDVALUE: command not found 2 *-* unassignedvalue >>> "UNASSIGNEDVALUE" +++ "RC(127)"
Variables can be assigned values more than once. The below program shows how the value of X can be assigned a value multiple times.
Example
/* Main program */ X = 40 X = 50 say X
The output of the above program will be as follows −
50
Printing Variables
The values of variables are printed using the say command. Following is an example of printing a variety number of variables.
Example
/* Main program */ X = 40 /* Display an Integer */ say X Y = 50.5 /* Display a Float */ say Y Z = "hello" /* Display a string */ say Z
The output of the above program will be as follows −
40 50.5 hello
Rexx – Operators
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
Rexx has various types of operators which are also explained in detail as follows −
- Arithmetic operators
- Relational operators
- Logical operators
- Bitwise operators
Arithmetic Operators
The Rexx language supports the normal Arithmetic Operators as any the language. Following are the Arithmetic Operators available in Rexx.
Operator | Description | Example |
---|---|---|
+ | Addition of two operands | 1 + 2 will give 3 |
− | Subtracts second operand from the first | 1 – 2 will give -1 |
∗ | Multiplication of both operands | 2 ∗ 2 will give 4 |
/ | Division of numerator by denominator | 2 / 2 will give 1 |
// | Remainder of dividing the first number by the second | 3 // 2 will give 1 |
% | The div component will perform the division and return the integer component. | 3 % 2 will give 1 |
Relational Operators
Relational Operators allow of the comparison of objects. Following are the relational operators available in Rexx. In Rexx the true value is denoted by 1 and the false value is denoted by 0.
Operator | Description | Example |
---|---|---|
== | Tests the equality between two objects | 2 = 2 will give 1 |
< | Checks to see if the left object is less than the right operand. | 2 < 3 will give 1 |
=< | Checks to see if the left object is less than or equal to the right operand. | 2 =< 3 will give 1 |
> | Checks to see if the left object is greater than the right operand. | 3 > 2 will give 1 |
>= | Checks to see if the left object is greater than or equal to the right operand. | 3 > 2 will give 1 |
Logical Operators
Logical Operators are used to evaluate Boolean expressions. Following are the logical operators available in Rexx.
Operator | Description | Example |
---|---|---|
& | This is the logical “and” operator | 1 or 1 will give 1 |
| | This is the logical “or” operator | 1 or 0 will give 1 |
This is the logical “not” operator |