1 / 45

z/VM Module 6: The REXX Programming Language

z/VM Module 6: The REXX Programming Language. Module Objectives. Data structures IF-THEN-ELSE SELECT LOOPS Data formats An example of formatting numbers and strings are: FORMAT( )  numerical SUBSTR( )  string manipulation Input/Output (I/O) functions STREAM( ) function

daktari
Télécharger la présentation

z/VM Module 6: The REXX Programming Language

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. z/VMModule 6: The REXX Programming Language

  2. Module Objectives • Data structures • IF-THEN-ELSE • SELECT • LOOPS • Data formats • An example of formatting numbers and strings are: • FORMAT( )  numerical • SUBSTR( )  string manipulation • Input/Output (I/O) functions • STREAM( ) function • CHARIN, LINEIN, CHAROUT, LINEOUT instructions • Parameters • To retrieve parameters use: • ARG, PULL, etc.

  3. Objectives • Describe REXX and how it works with z/VM • Describe how to write REXX programs using: • Comments • Keywords and literal strings • Clauses • Syntax error messages • Explain the use of REXX variables with names, values, and assignments

  4. Objectives continued • Understand which expressions can be used within a REXX clause: • Operators and terms • Comparisons (equal, and, or) • Functions • Learn the control statements for manipulating data flow: • IF – THEN • ELSE keyword • DO LOOPS (repetitive and conditional) • Selection

  5. Objectives continued • Explain arithmetic, text, and conversational expressions for manipulating and gathering data • Show how to issue CMS and CP commands within a REXX EXEC • Explain the subcommands and macros used in REXX EXECs • Introduce REXX subroutines

  6. What is REXX? • REstructured eXtended eXecutor language • A versatile, easy to use, structured programming language • A programming language that is easy for both computer professionals and general users to learn and use • A compiler can be used to translate REXX source programs into compiled programs

  7. Features of REXX • Ease of use • Free format • Interpreted • Built-in functions • Parsing capabilities • Powerful debugger • Relationship with z/VM

  8. How a Program Works • A REXX program is a list of instructions, something like a recipe • A computer communicates with users through questions displayed and answers typed in

  9. Comments in REXX Programs • Comments in programs: • /* . . . */, this is used for descriptions and explanations • Comments with special meaning to CMS • To determine you are writing a REXX program the first line must contain /* . . . */

  10. Keywords and Literal Strings • Keywords are instructions that describe an action, such as PULL, IF, and SAY. • REXX reads each individual clause, then processes it before going on to the next (interpreted language). • A literal string is a set of characters bounded by quotation marks. • REXX processes a clause containing a variable by substituting the variable name with the stored data.

  11. REXX Clauses • REXX programs consist of these types of clauses: • Instruction • Assignment • Label • Null • Commands

  12. REXX Syntax Errors

  13. REXX Variables

  14. Names, Values, and Assignments • Information stored in a variable is called its value. • It is possible to make variable names anything, but a good idea to create meaningful names. • An instruction that stores a value in a variable or changes its value is called an assignment. • In formal terms, the syntax might look like this: • symbol = expression

  15. Other Assignments • The PULL instruction: • Pauses the running program to allow the user to enter data • Can be used to pull in each piece of data or allow the user to enter multiple amounts of data separated by spaces • The ARG instruction: • Like PULL, but data items are entered at the command prompt with the program name

  16. Assignments and Instructions • One way to write this EXEC is: /* SUBMUL1 EXEC */ ARG first second say first “-” second “=” first-second say first “*” second “=” first*second • Another way to write this EXEC is: /* SUBMUL2 EXEC */ say “Enter two numbers to multiply and subtract.” pull first second say first “-” second “=” first-second say first “*” second “=” first*second

  17. REXX Expressions • Operators and terms: • Operators include +, -, /, %, *, || • Operators manipulate numbers, strings in quotes, variables, results from function calls and evaluated expressions • Parentheses: • The language processor evaluates the expression inside the parentheses first • The value of 10 * ( 3 || 4 ) is: 340

  18. REXX Expressions (Comparison, True, and False) • Comparisons: • > Greater than • = Equal • < Less than • TRUE, the computed result is 1 • say 4 < 7 • /* represents a “1”, which means TRUE */ • FALSE, the computed result is 0 • say “Chalk” = “Cheese” • /* represents a “0”, which meaning FALSE */

  19. REXX Expressions ( =, &, | ) • The equal sign (=) can have two meanings • Can be an assignment if found at the beginning after the symbol • An equal sign anywhere else stands for the comparison operator • Use the AND (&) operator to write an expression that is true when everything else is also true • Use the OR (|) operator when any part of an expression can be true

  20. REXX Functions • Function calls can be written anywhere in an expression. • The function performs the computation named by the function and returns the result. • When the value of the function has been calculated, the result is put back into the expression in place of the function call. • An example is: • say 7 + HALF(6) /* becomes 7 + 3 which says “10” */

  21. Control Statements: IF – THEN

  22. Examples and Notes: IF - THEN • The THEN instruction may be an assignment, command, or keyword. • The NOP instruction can be used when no operations are necessary. • An important property of the THEN keyword is that is does not need to start a clause, therefore a semicolon is not needed. • Another example is: • If answer=‘YES’ then say ‘OK!’; else say ‘Why not?’

  23. Control Statements: ELSE Keyword

  24. REXX Loops

  25. Repetitive DO Loops

  26. Conditional DO Loops • Conditional loops continue to be executed as long as some condition is satisfied. • The simplest way to code these loops is to use DO FOREVER and LEAVE instructions.

  27. Conditional Loops: The Choice • There are three kinds of Conditional Loops • The decision is made before processing starts • Checking occurs before entering the loop and continues after each iteration. • The decision is made after the first pass through the loop and again after every subsequent pass. • Data is requested for the user. • The decision is made during each pass. • The decision to leave might depend on information obtained during the loop.

  28. The SELECT Instruction

  29. A SELECT Instruction SELECT WHEN morning THEN DO say “Take shower” say “Eat breakfast.” say “Get ready for work.” end WHEN afternoon THEN DO until ans=Y say “Did you eat lunch? (Y/N) PARSE UPPER PULL ans end otherwise say “It is in the evening -- get ready for bed!!” end

  30. Arithmetic • The addition, subtraction and multiplication operations are performed in the usual way. • +  Addition • -  Subtraction • *  Multiplication • **  Power function • The result of a % operation is the whole number portion. The remainder is dropped. • The result of a // operation is the remainder portion. The whole number is dropped. • The result of a / operator is a combination of both operations above.

  31. Text - Concatenation

  32. Text – String Manipulation • SUBSTR() Function: • To select a part of a string to use: • WORD = “reveal” • say substr(WORD, 2, 3) /* says “eve” */ • LENGTH() Function: • To find out the length of a REXX variable: • WORD = "reveal" • say length(WORD) /* says "6" */

  33. Text – String Manipulation continued • COPIES(): • Produces a number of copies of the string. The arguments are: • The string to be copied • The number of copies required • LEFT(): • Obtains a string that is padded or truncated on the right • RIGHT(): • Obtains a string that is padded or truncated on the left

  34. Conversations – SAY and PULL • The SAY instruction and its expression are computed and the result is displayed as a new line on the screen. • The PULL instruction is able to collect an answer that has been displayed by the SAY instruction. • The PARSE PULL instruction brings in the data just as it is, without converting the lowercase letters to uppercase. • The UPPER instruction translates the value of one or more variables to uppercase.

  35. Conversation – Parsing Words • PULL can also fetch each word into a different variable • Using the period as a place holder in this statement (PULL . . lastname .) means to discard the first two words and assign the third word to lastname.

  36. Issuing Commands to CMS and CP • The language processor can operate in a number of environments. • Use quotes to avoid errors when writing CMS and CP commands within REXX.

  37. Issuing Commands – Return Codes • More examples: 1) access 591 591 DMSACC113S B(591) not attached or invalid device address Ready (00100); 2) copyfile profile exec a = = b (for luck Invalid parameter LUCK in the option FOR field Ready (00024); 3) erase junk exec File JUNK EXEC A not found Ready (00028)

  38. Why Use a Compiler? • Advantages of compiling REXX EXECS • Source can be hidden from end users • Load modules are loaded into memory faster • Compile programs using this CMS command: • REXXD [source-file-identifier]

  39. How to Use the Compiler

  40. XEDIT Subcommands and Macros • The first word on the command line is assumed to be a subcommand • Words that are not subcommands are interpreted as macros

  41. Subroutines

  42. Conclusion • REXX was created as a procedural language that allows programs and algorithms to be written in a clear and structured way. • Topics in this module: • Comments • Clauses • Variables • Expressions • Control statements: • IF THEN • ELSE • Loops • Selection

  43. Glossary Clause – a line of code or a statement within a REXX program Parsing – manipulates character strings to let your program read and separate characters, number, and mixed inputs PL/I – was developed as the universal programming language, where definitions were not needed

  44. Glossary • REXX – REstrutured eXtneded eXecutor language, a versatile, easy to use structured programming language that is an integral part of z/VM. • REXXCompiler – translates REXX source programs into compiled programs. (Compiled programs run much faster than interpreted programs.)

  45. References z/VM: REXX/VM User’s Guide –Version 3 Release 1.0  SC24-5962-00 The REXX Language: A Practical Approach to Programming –by Michael Cowlishaw Website: Rexx Language Association

More Related