1 / 17

Linux on zSeries: Supplemental REXX module

Linux on zSeries: Supplemental REXX module. What is REXX?. REXX is a procedural programming language It facilitates writing programs and algorithms to be written in a clear and structured way

mgarner
Download Presentation

Linux on zSeries: Supplemental REXX module

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linux on zSeries:Supplemental REXX module

  2. What is REXX? • REXX is a procedural programming language • It facilitates writing programs and algorithms to be written in a clear and structured way • REXX has been designed to make easy the manipulation of the kinds of symbolic objects that people normally deal with such as words and numbers • REXX has the capability to issue commands to its host environment and to call programs and functions written in other languages • REXX is also designed to be independent of its supporting system software when such commands are kept to a minimum

  3. General programming using REXX • REXX provides powerful character and arithmetical abilities in a simple framework • It can be used to write simple programs with a minimum of overhead, but it can also be used to write robust large programs • It can be used for many of the programs for which BASIC would otherwise be used, and its layout may look somewhat similar to that of a structured BASIC program • A simple program in REXX looks like this: • /* Count to ten and add the numbers up */ • sum = 0 • do count = 1 to 10 • say count sum = sum + count • end • say "The sum of these numbers is" sum"."

  4. Macro programming using REXX • Many applications are programmable by means of macros • In Unix almost every application has a different macro language • REXX is a character manipulation language, providing a macro language useable by all these applications and providing an easy-to-use and consistent interface across all applications • An example of such a system is on CMS and on the Amiga • REXX is freely available on Unix applications, applications can start to appear which have REXX as their macro language • Two products already exist • Workstation Group's Uni-XEDIT • Mark Hessling's THE • REXX treats any instruction that it doesn't immediately recognize as an expression which it evaluates and passes to the host environment as a command

  5. A simple XEDIT macro in REXX • /* this XEDIT macro centers the line containing the cursor. • width = 72 /* Width within which to centre the line • "extract /cursor /curline" /* location of cursor and current line # • if cursor.3=-1 /* if cursor is not on a line... • then "emsg Cursor not in a data line“ /* then give an error message • else do restore=curline.2-cursor.1 /* how far cursor is from current • ":"||cursor.3 /* make cursor line current • "extract /curline“ /* get the current line • "replace" centre(strip(curline.3),width) /* centre the current line • restore /* restore old current line • end */ end

  6. Other applications of REXX • REXX can be used as an "application glue" language • similar to how shell scripts are often used • REXX is able to pass arbitrary command strings for execution by its environment • It can be used to execute Unix programs as well as providing the control language necessary for testing things such as parameters and return codes • REXX is often executed by an interpreter, and this permits rapid program development • This creates a productivity advantage that makes the language very suitable for modeling applications and products • Useful for prototype development • REXX is also easy to debug • Once a design has been shown to work satisfactorily, it can be easily recoded in another language if that is required for performance or other reasons • The design of REXX is such that the same language can effectively and efficiently be used for many different applications that would otherwise require the learning of several languages

  7. Creating a REXX program • As with every other programming language you have ever learned, lets start with a "Hello world!“ program • Write a file called "hello.rexx" containing: “Hello World” • Use a text editor or `cat' the text into the file • This program says "Hello world!" */ say "Hello world!" • It consists of a comment saying what the program does • an instruction which does it • "say" is the REXX instruction which displays data on the terminal • The method of executing a REXX program varies between implementations: Using rexx/imc: • rexx hello • Notes about this command: rexx is the name of the interpreter • In order for this command to work, the interpreter must lie on your current PATH • The word "hello" which comes after the command "rexx" is the name of your program • Ordinarily, the interpreter adds ".rexx" to the name you give in order to construct the name of the file to execute

  8. Arithmetic with REXX • REXX has a wide range of operators, which can deal with very high precision numbers • Here is an example of a program which does arithmetic • Make a file called "arith.rexx" containing the following • This program inputs a number and does some calculations on it • pull a • b=a*a • c=1/a • d=3+a • e=2**(a-1) • say 'Results are:' a b c d e • Run it with "rexx arith" and type in a positive integer • rexx arith 5 • Results are: 5 25 0.2 8 16 • The original number (5), its square (25), its reciprocal (0.2), the number plus three (8) and two to the power of one less than the number (16) • *Note: you can put more than one instruction on a line in a REXX program • Simply place a semicolon between the instructions, like this: • /* This program inputs a number and does some calculations on it • pull a; b=a*a; c=1/a; d=3+a; e=2**(a-1); say 'Results are:' a b c d e

  9. Arithmetic in REXX • Variables: in this example a, b, c, d and e are variables • Assign a value to a variable by typing its name "=" and a value • The value can be used in an expression simply by typing its name • Input: • By typing "pull a" you tell the interpreter to ask the user for input and to store it in the variable a • Arithmetic: • The usual symbols (+ - * /) as well as ** (to-power) were used to perform calculations • Parentheses were used to group together an expression • String expressions: • The result of the program is the string expression 'Results are:' a b c d e • There are six components: the string constant 'Results are:' and the five variables • They are attached together with spaces into one string expression, which the "say" command then displays on the terminal • A string constant is any sequence of characters which starts and ends with a quotation mark (" or ‘)

  10. Errors • If you input an invalid data type, such as a 3.4 in type integer in the program, you would get an error, because the ** (to-power) operator is only designed to work when the second parameter (that is, the power number) is an integer • For example: • rexx arith 3.4 I 6 +++ e=2**(a-1) • Result prompt: Error 26 running arith.rexx, line 6: Invalid whole number • If you typed zero, you might see the following • rexx arith 0 I 4 +++ c=1/a • Error 42 running arith.rexx, line 4: Arithmetic overflow or underflow • If you type a sequence of characters which is not a number, you might see the following since it will not complain about the characters you entered, but rather about the fact that the program tries to use it as a number • rexx arith I hello I 3 +++ b=a*a • Error 41 running arith.rexx, line 3: Bad arithmetic conversion • Each case produces a syntax error followed by a traceback starting with the line which caused the error and a description of the error • This information is helpful for debugging as it shows where the error occurred and what caused it

  11. Untyped data • Data in REXX are untyped meaning that the contents of a variable or the result of an expression can be any sequence of characters (what the characters are used for matters only to the programmer) • This allows you to be able to input either a number or a sequence of letters and store it in the variable even though the actual arithmetic functions won’t work • Strings can be added together by: • Placing a space in between them • Use the abuttal operator • simply types the two pieces of data next to each other without a space • However, if you type an "a" next to a "b“ creating an "ab“ this is the name of another unrelated variable and might not be appropriate • The concatenation operator ”||” • This operator also concatenate the strings without a space in between • For example to demonstrates concatenation and the use of untyped data • a='A string' b='123' c='456' d=a":" (b||c)*3 • say d • The result is: "A string: 370368“ • This is because (b||c) is the concatenation of strings b and c, which is "123456“, that sequence of characters happens to represent a number, and so it can be multiplied by 3 to give 370368, finally, that is added with a space to the concatenation of a with ":" and stored in d

  12. Regina REXX • This is a version of REXX available for use on Linux • The library containing Regina is available either as a static library or as a dynamically loadable library • The only functional difference between the two libraries is that the ability to dynamically load REXX external function packages via the built-in function; RxFuncAdd, is only available with the dynamically loadable library • The Regina distribution also includes a front end to the Regina library, to enable the execution of REXX programs directly from the command line (Linux shell)

  13. Ports of Regina

  14. Executing REXX programs with Regina • From the command line: • regina [switches] [program] [program parameters] where: • regina is the name of the Regina executable • switches are optional switches • program the name of the REXX program to be executed • If no program name is specified, Regina waits for REXX commands to be typed in and will execute those commands when the appropriate end-of-file character • program parameters any optional parameters to be passed to the REXX program.

  15. Executing REXX • REXX programs to be executed by Regina can take advantage of magic numbers • The first line of a REXX program consists of the special sequence of #! followed by the full file name of the Regina executable • This allows you to invoke the program simply by typing the name of the REXX program on the command line followed by any parameters you wish to pass to the REXX program • The file name must also have the appropriate execute bit set for this to work • For example suppose the REXX program, myprog, contained: • #!/usr/local/bin/regina • Parse Version ver • Say ver • Upon executing this program by typing myprog, the Linix shell program would execute the program /usr/local/bin/regina and pass the remainder of the lines in the file to this program via stdin

  16. REXX Switches • -t[trace parameter] turns on the specified tracing level • -a keeps all command line parameters from being passed to Regina as a single argument • -r Run Regina in restricted mode

  17. External REXX programs • Regina searches for REXX programs, using a combination of the REGINA_MACROS environment variable and the addition of filename extensions • This applies to both external function calls and the program specified on the command line • For example with this call: Call myextfunc arg1, arg2 • Regina first looks for a file called myextfunc in the current directory • It then looks in each directory specified in the REGINA_MACROS environment variable for a file called myextfunc • Next it would look for a file called myextfunc.rexx in the current directory followed by each other directory in REGINA_MACROS • The process continues with “.rex”, “.cmd” and “.rx” • If none of these are found, Regina complains that the external function is unknown

More Related