Rexx Programming Language

Page 1

G

amingmalt Next Level of Gaming

www.gamingmalt.com


Rexx

About the Tutorial 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. It is also very helpful for developing small programs that perform various text file transformations. This is an introductory tutorial that covers the basics of Rexx and how to deal with its various components and sub-components.

Audience This tutorial has been prepared mainly for those professionals who are within the IT industry, working as specialists in the field of Scripting and Macro Languages. It is very useful for those professionals who work on Data Processing, text and also for generating reports. This tutorial is intended to make you comfortable in getting started with Restructured Extended Executor (Rexx) and its various functions.

Prerequisites It is an elementary tutorial and you can easily understand the concepts explained here with a basic knowledge of how a company or an organization deals with its scripting languages and programs. However, it will help if you have some prior exposure on programming languages, data processing, and generating reports.

Copyright and Disclaimer ďƒŁ Copyright 2016 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at contact@gamingmalt.com contact@tutorialspoint.com

i


Rexx

Table of Contents About the Tutorial ............................................................................................................................................ i Audience........................................................................................................................................................... i Prerequisites..................................................................................................................................................... i Copyright and Disclaimer .................................................................................................................................. i Table of Contents............................................................................................................................................. ii

1. REXX – OVERVIEW ................................................................................................................ 1 Features of Rexx .............................................................................................................................................. 1

2. REXX – ENVIRONMENT ......................................................................................................... 3 Downloading Rexx ........................................................................................................................................... 3

3. REXX – INSTALLATION .......................................................................................................... 5 4. REXX – INSTALLATION OF PLUGIN-INS ................................................................................ 13 Installation in Eclipse ..................................................................................................................................... 13

5. REXX – BASIC SYNTAX ......................................................................................................... 18 General Form of a Statement......................................................................................................................... 18 Executing Commands..................................................................................................................................... 19 Keywords in Rexx........................................................................................................................................... 20 Comments in Rexx ......................................................................................................................................... 20

6. REXX – DATATYPES ............................................................................................................. 22 Built-in Data Types......................................................................................................................................... 22

7. REXX – VARIABLES .............................................................................................................. 26 Different Types of Variable Functions ............................................................................................................ 26

8. REXX – OPERATORS ............................................................................................................ 29 Arithmetic Operators ..................................................................................................................................... 29 ii


Rexx

Relational Operators...................................................................................................................................... 30 Bitwise Operators .......................................................................................................................................... 32 Operator Precedence ..................................................................................................................................... 34

9. REXX – ARRAYS ................................................................................................................... 35 Creating Arrays .............................................................................................................................................. 35 Assigning Values to an Array Element ............................................................................................................ 36 Copying Arrays ............................................................................................................................................... 37 Iterating through array elements ................................................................................................................... 37 Two-dimensional Arrays ................................................................................................................................ 38

10.

REXX – LOOPS ................................................................................................................. 39

The do Loop ................................................................................................................................................... 39 The do-while Loop ......................................................................................................................................... 41 The do-until Loop........................................................................................................................................... 43 Controlled Repetition .................................................................................................................................... 45

11.

REXX – DECISION MAKING .............................................................................................. 47

If statement ................................................................................................................................................... 47 If-else statement............................................................................................................................................ 49 Nested If Statements ..................................................................................................................................... 51 Select Statements .......................................................................................................................................... 53

12.

REXX – NUMBERS............................................................................................................ 55

ABS ................................................................................................................................................................ 55 MAX............................................................................................................................................................... 56 MIN ............................................................................................................................................................... 57 RANDOM ....................................................................................................................................................... 57 SIGN............................................................................................................................................................... 58

iii


Rexx

TRUNC ........................................................................................................................................................... 58

13.

REXX – STRINGS .............................................................................................................. 60

left ................................................................................................................................................................. 60 right ............................................................................................................................................................... 61 length ............................................................................................................................................................ 61 reverse........................................................................................................................................................... 62 compare ........................................................................................................................................................ 62 copies ............................................................................................................................................................ 63 substr............................................................................................................................................................. 64 pos ................................................................................................................................................................. 64 delstr ............................................................................................................................................................. 65

14.

REXX – FUNCTIONS ......................................................................................................... 67

Defining a Function ........................................................................................................................................ 67 Working with Arguments ............................................................................................................................... 68 Recursive Functions ....................................................................................................................................... 69

15.

REXX – STACKS ................................................................................................................ 70

16.

REXX – FILE I/O................................................................................................................ 72

Reading the Contents of a File a Line at a Time .............................................................................................. 72 Reading the Contents of a File at One Time ................................................................................................... 73 Writing Contents to a File .............................................................................................................................. 74

17.

REXX – FUNCTIONS FOR FILES ......................................................................................... 75

Lines .............................................................................................................................................................. 75 stream ........................................................................................................................................................... 76 charin ............................................................................................................................................................ 77 chars .............................................................................................................................................................. 78

iv


Rexx

charout .......................................................................................................................................................... 79

18.

REXX − SUBROUTINES ..................................................................................................... 80

Defining a Subroutine .................................................................................................................................... 80 Working with Arguments ............................................................................................................................... 81 Different Methods for Arguments ................................................................................................................. 81

19.

REXX – BUILT-IN FUNCTIONS........................................................................................... 83

ADDRESS ........................................................................................................................................................ 83 BEEP .............................................................................................................................................................. 83 DataType ....................................................................................................................................................... 84 DATE .............................................................................................................................................................. 85 DIGITS ............................................................................................................................................................ 86 ERRORTEXT .................................................................................................................................................... 86 FORM............................................................................................................................................................. 87 TIME .............................................................................................................................................................. 87 USERID ........................................................................................................................................................... 89 XRANGE ......................................................................................................................................................... 89 X2D ................................................................................................................................................................ 90 X2C ................................................................................................................................................................ 90

20.

REXX – SYSTEM COMMANDS .......................................................................................... 92

dir .................................................................................................................................................................. 92 Redirection Commands.................................................................................................................................. 93 The ADDRESS Function .................................................................................................................................. 94

21.

REXX – XML ..................................................................................................................... 95

What is XML? ................................................................................................................................................. 95 xmlVersion .................................................................................................................................................... 97

v


Rexx

xmlParseXML ................................................................................................................................................. 97 xmlFindNode ................................................................................................................................................. 98 xmlEvalExpression ......................................................................................................................................... 99

22.

REXX – REGINA.............................................................................................................. 101

b2c ............................................................................................................................................................... 102 bitcomp ....................................................................................................................................................... 103 bittst ............................................................................................................................................................ 103 find .............................................................................................................................................................. 104 getenv.......................................................................................................................................................... 104 getpid .......................................................................................................................................................... 106 hash ............................................................................................................................................................. 106 justify........................................................................................................................................................... 107 putenv ......................................................................................................................................................... 107 directory ...................................................................................................................................................... 108 chdir ............................................................................................................................................................ 108 randu ........................................................................................................................................................... 109

23.

REXX – PARSING ............................................................................................................ 110

Positional Parsing ........................................................................................................................................ 112

24.

REXX – SIGNALS............................................................................................................. 114

Trap Label Transfer Activation / Deactivation .............................................................................................. 116

25.

REXX – DEBUGGING ...................................................................................................... 117

Trace in Batch Mode .................................................................................................................................... 117 Trace Function ............................................................................................................................................. 118 Setting Trace Value ...................................................................................................................................... 119 Interactive Tracing ....................................................................................................................................... 119

vi


Rexx

26.

REXX – ERROR HANDLING ............................................................................................. 121

Trapping Errors ............................................................................................................................................ 121

27.

REXX – OBJECT ORIENTED ............................................................................................. 123

Class and Method Declarations.................................................................................................................... 123 Getter and Setter Methods .......................................................................................................................... 124 Instance Methods ........................................................................................................................................ 124 Creating Multiple Objects ............................................................................................................................ 125 Inheritance .................................................................................................................................................. 126

28.

REXX – PORTABILITY...................................................................................................... 128

29.

REXX – EXTENDED FUNCTIONS ..................................................................................... 129

b2c ............................................................................................................................................................... 129 bitclr ............................................................................................................................................................ 129 bitcomp ....................................................................................................................................................... 130 buftype ........................................................................................................................................................ 130 crypt ............................................................................................................................................................ 131 fork .............................................................................................................................................................. 132 getpid .......................................................................................................................................................... 132 hash ............................................................................................................................................................. 132

30.

REXX – INSTRUCTIONS .................................................................................................. 134

address ........................................................................................................................................................ 134 drop ............................................................................................................................................................. 135 interpret ...................................................................................................................................................... 136 nop .............................................................................................................................................................. 136 Pull .............................................................................................................................................................. 137 push ............................................................................................................................................................. 137

vii


Rexx

31.

REXX – IMPLEMENTATIONS .......................................................................................... 139

OoRexx ........................................................................................................................................................ 139 Netrexx ........................................................................................................................................................ 139 Brexx ........................................................................................................................................................... 140

32.

REXX – NETREXX............................................................................................................ 141

Setting up NetRexx ...................................................................................................................................... 141 Running the First NetRexx Program ............................................................................................................. 142 Indexed Strings ............................................................................................................................................ 143 Multiple Indexes .......................................................................................................................................... 143 ask Command .............................................................................................................................................. 143 digits Command ........................................................................................................................................... 144 form Command............................................................................................................................................ 144 length Command ......................................................................................................................................... 145 version Command ........................................................................................................................................ 145 trace Command ........................................................................................................................................... 145

33.

REXX – BREXX ................................................................................................................ 147

Setting up BRexx .......................................................................................................................................... 147 acos Command ............................................................................................................................................ 148 cos Command .............................................................................................................................................. 148 sin Command ............................................................................................................................................... 149 asin Command ............................................................................................................................................. 149 tan Command .............................................................................................................................................. 150 atan Command ............................................................................................................................................ 150 mkdir Command .......................................................................................................................................... 151 rmdir Command........................................................................................................................................... 151 dir Command ............................................................................................................................................... 152 viii


Rexx

34.

REXX − DATABASES ....................................................................................................... 153

Database Connection ................................................................................................................................... 154 Creating a Database Table ........................................................................................................................... 154 Operations on a Database Table .................................................................................................................. 155

35.

REXX – HANDHELD & EMBEDDED PROGRAMMING ...................................................... 160

36.

REXX – PERFORMANCE ................................................................................................. 161

37.

REXX – BEST PROGRAMMING PRACTICES ..................................................................... 163

38.

REXX – GRAPHICAL USER INTERFACE ............................................................................ 165

Environment Setup ...................................................................................................................................... 165 Basic Program .............................................................................................................................................. 171 Creating Menus ........................................................................................................................................... 172

39.

REXX − REGINALD.......................................................................................................... 174

Environment Setup ...................................................................................................................................... 174 Other Functions Available ............................................................................................................................ 176

40.

REXX – WEB PROGRAMMING........................................................................................ 177

ix


1. Rexx – Overview

Rexx

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 1


Rexx 

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 http://www.oorexx.org/

2


2. Rexx – Environment

Rexx

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

Disk Space

Operating System Version

2 GB RAM (recommended) No minimum requirement. Preferably to have enough storage to store the programs which will be created using Rexx.

Rexx can be installed on Windows, Ubuntu/Debian, Mac OS X.

Downloading Rexx To download Rexx, you should use the following URL – http://www.oorexx.org/download.html

3


Rexx 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. 4


3. Rexx – Installation

Rexx

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.

5


Rexx

6


Rexx Step 3: Click on the I Agree button to proceed.

Step 4: Accept the default components and then click on the next button.

7


Rexx 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.

8


Rexx 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.

9


Rexx 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.

10


Rexx 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.

11


Rexx Step 13: Click on the Finish button to complete the installation.

12


Rexx End of ebook preview If you liked what you saw… Buy it from our store @ https://store.tutorialspoint.com

Thank You! End of ebook preview If you liked what you saw… Buy it from our store @ https://www.gamingmalt.com/

13


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.