Upload
siranjeevi-mohana-raja
View
52
Download
4
Embed Size (px)
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 1/62
Howard Fosdick(C) 2006 FCI
Free Rexx ! Everything You Ever Wanted to Know
About Rexx (but were afraid to ask)
Version 2.0
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 2/62
Who Am I?
• Presentation by Howard Fosdick,
author of Rexx Programmer’s Reference
• Find the book at www. Amazon.com/rexx
• This presentation is published under the OpenPublication License (OPL).
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 3/62
Viewpoint / Purpose
• All languages have their strengths & roles
• Not here to “put down” other languages
• Here to present Rexx’s strengths and
discuss where it fits in your toolbox
(1) Know where Rexx fits(2) Teach you to script it in < 2 hours !
Goals:
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 4/62
Outline
1. Why Scripting ?2. Why Rexx ?3. Rexx Tutorial4. Further Info
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 5/62
I. Why Scrip t ing ?
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 6/62
2 Big Software Trends Converge
Ka-Boom!
Free andOpen Source
Scripting
Perl,Python,Rexx, Tcl/Tk,Bash,Korn,Ruby,others
Java,C/C++,
COBOL Visual Basic,VBScript,
WSH
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 7/62
• Interpreted
• High-level
• Glue language
• General purpose
• Free / open source
• Universal
• Portable code• Transferable skills
• Standardized(8 of 9 free Rexxes meet stds)
• Dynamic• Sizing (variables & arrays)• Memory management
• No “variable declarations” • No “data typing” • Inte rated debu er
Rexx:
What‟s a Scr ipt ing Language ?
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 8/62
Scripting Vs. Traditional Languages
-- High level
-- Interpretive-- More productive-- Varying degrees of
automatic variable management-- Shifts burden to the machine
-- “Glue” languages -- Acceptable execution speed
-- Lower level
-- Compiled-- More detail-oriented-- Manual variable management-- Pre-declared variables-- More programmer effort
-- “Coding” languages -- Optimize execution speed Rexx, Perl, Python,Tcl/Tk, Ruby, others C/C++, COBOL,
Java, Pascal, others
Scripting Traditional
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 9/62
When to Use Rexx
-- Productivity-- Reliability-- Quick development
-- Glue language-- Prototyping-- Systems administration-- OS extensions-- Portable apps-- Mainframe migrations
-- Embedded programming-- Handhelds-- Text processing-- Interactive development /
debugging
-- Optimal execution speedis required
-- Systems -level programming
(No BIOS interrupts, directaddressing, etc.)
No Yes
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 10/62
Performance
Year-- 1981 1988 1993 1998 2005Mhz-- 4.77 8 66 266 3 ghzCPU-- 8088 386 486 PII PIV
704k
10k
200k
3M
Ratio of compiler to interpreter speed remains constant whileprocessor speeds increaseexponentially
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 11/62
II. Why Rexx ?
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 12/62
Why Rexx Vs Other Scripting Languages ?
“ Easy bu t Powerfu l ”
• FAST coding !
• Reliable code
• Easy to code right out of memory
• Maintainable code
• 70%+ of IT does maintenance
• This determines your code‟s longevity • Saves your company $$$
Ease of use benefits exper ienced developers ...
“Easy but Powerful”
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 13/62
Rexx uses specific technologiesto tie them together
Why Rexx Vs Other Scripting Languages ?
Power Simplicity
Conf l ict !
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 14/62
Power Through Simplicity by… • Small instruction set, w/ power in the functions• Extensible• Call external functions just like internal• Glue language (uses OS commands, interfaces,
DLLs, shared libraries, services, objects, etc.)
• Minimal syntax• Minimal special characters, variables, etc.
• Automated memory management• Automated variable management
• No data definitions• No data typing• Dynamic array sizes
• Dynamic string or variable lengths
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 15/62
Power Through Simplicity…
Rexx presents a radically differentphilosophy on how to achieve
power than the “Unix tradition”languages (Perl, Bash, Korn, Awk, etc.)
Rexx presents a unique
sc r ipt ing paradigm
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 16/62
The Language Structure Makes Rexx Easy
Operators Arithmetic
Comparison
Logical
String 2 dozen Instructions
70 Built-inFunctions
Other Features OS commands, external functions, DLLs, APIs, widgets, etc.
Learn fromthe inside out
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 17/62
Rexx Runs Everywhere… Linux-- all versionsUnix-- all versionsBSD-- all versionsWindows-- all versionsMac OS-- all versionsDOS all versions (32- and 16- bit), IBM PC-DOS 2000 and 7
Handhelds-- Windows CE / Mobile / PPC / etc, Palm OS,Symbian/EPOC32, EPOC, DOS emulation
Embedded-- Embedded Linux, DOS, Windows variants
Mainframes-- z/OS, z/VM, z/VSE (all versions)IBM iSeries-- i5/OS, OS/400 (all versions)
Many others-- AmigaOS, AROS, MorphOS, OpenVMS, BeOS,OpenEdition, AtheOS/Syllable, SkyOS,QNX (QNX4/QNX6), OS/2, eCS, osFree, more…
Rexx predominates on systems in red
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 18/62
Rexx Has Crit ical Mass ...
Open sou rce, general pu rpos e scr ipt ing languages wi th cri t ical mass --
* Run everywhere (on all major OS‟s and platforms) * Have strong standards* Enjoy wide use and offer good support
* Internationally* In many spoken languages
* Offer thousands of free tools and scripts* Interface to everything (databases, web programming, GUIs, etc, etc)
NOTE-- The chart excludes non-o en source e VB VBScri t and non- eneral ur ose e PHP scri tin lan ua es
Cri t ical mass
Do no t have cri t ical mass
Perl
Python
Rexx, Tcl/Tk, Ruby
Many other good languages
(Ko rn, C-shel l, bash, Bourne, Lua,
Mumps, etc)
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 19/62
The Free Rexx Interpreters
Windows, DOS (32/16 bit),Windows CE, Linux, Unix,Mac OS, AmigaOS, others
All major operating systems
Windows
Unix, Linux, BSD
Windows Palm OS
WindowsLinux, Windows,Solaris, AIX
Any JavaEnvironment
Regina Rexx/imc
Reginald
roo!
Rexx for Palm OS
r4
BRexx
NetRexx Open Object
Rexx OOP
extensions
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 20/62
Rexx Free Tools and Interfaces • Over 2000 free tools & scripts for Rexx. Examples:
• SQL database access• GUIs
• XML• Web programming• Math libraries• Regular Expressions
• Code managers• Communications functions• OS interface libraries• Graphics
• Speech, MIDI, sound• . . . you name it . . .
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 21/62
III. Let’s Code !
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 22/62
/*******************************************************************/ /* Find Payments: */ /* Reads accounts lines one by one, and displays overdue */ /* payments (lines containing the phrase PAYMENT_OVERDUE). */ /*******************************************************************/ arg filein /* Read the input file name*/ do while lines(filein) > 0 /* Do while a line to read */
input_line = linein(filein) /* Read an input line */ if pos('PAYMENT_OVERDUE',input_line) > 0 then
say 'Found it:' input_line /* Write line if $ overdue */ end
Example Script # 1…
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 23/62
Simplicity in this script… • Minimal syntax • Minimal special characters and variables• Free format• Use spaces & blank lines however desired
• Case-insensitive (capitalize however you want)
• No explicit f i le def in i t ion • File is automatically OPEN‟ed and CLOSE‟d
• Automatic “declaration” of variables (see FILEIN and INPUT_LINE)
• No “data typing”
• All variables are strings• Numbers are strings that look like numbers
• Decimal arithmetic (portable, consistent results)• Automatic conversions where sensible
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 24/62
What is “Power” ? Is it the number of Lines of Code (LOC) ?
• Can reduce LOC by nesting functions
• But why write a complex “fortune-cookie” script ?
Power is not solving the problem in the fewest LOC!
Power is a deft script that solves the problemin a reliable, readable, maintainable manner
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 25/62
Example Script # 2…
arg filein fgrep PAYMENT_OVERDUE filein
This script does the same thing as Example #1
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 26/62
The Power of Glue Languages
• Rexx evaluates a statement, sends anythingthat is not Rexx to the “external environment” (by default this is the OS)
• Full power of a string-manipulation languageto direct external interfaces
• Inspect return code, command output, messages,and respond
• Rexx is a glue language
Structured Control Instructions
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 27/62
Structured Control Instructions Do End If If then else
Do While
(case) Call
Subroutineor Function
Select
Un Structured Control Instructions
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 28/62
Un-Structured Control Instructions Do Until
Do Forever
Iterate
Leave Signal
(goto)
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 29/62
Rexx Functions…
• 70 Built-in Functions:
• String manipulation (character, bit, hex)
• Word manipulation• I/O• Numeric• Environmental
• Conversion• Other
• 2 statements access external funct ion l ibrary
• Those functions are then coded just like built-ins
Example Script # 3
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 30/62
Example Script # 3… /*******************************************************************/ /* Code Lookup: */ /* Looks up the area code for the town the user enters. */ /*******************************************************************/ area. = '' /* Initialize array entries to null */ area.CHICAGO = 312 /* Define a table of area codes */area.HOMEWOOD = 708area.EVANSTON = 847
do while town <> '' /* Loop until user enters null line */ say 'For which town do you want the area code?'
pull town
if town <> '' then do if area.town = ''
then say 'Town' town 'is not in my database' else say 'The area code for' town 'is' area.town
end end
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 31/62
Simplicity in this script… • Array recognized by the period (area.)• Do not have to declare arrays or predefine their size• Sets all possible elements to null string (area. = „‟)
• Subscript array by any arbitrary string(con tent-addressable memory or associat ive memo ry )
• Arrays can be:• Dense or sparse
• Contain homogenous or heterogeneous elements• Represent records or C structs
• Expand to size of memory
• Automatic capitalization ( pull & array element names)
• Can always override Rexx‟s automation
Example Script # 4
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 32/62
Example Script # 4… /* Find Books: */ /* This program illustrates how arrays may be of any dimension */ /* in retrieving book titles based on their keyword weightings. */ keyword. = '' /* Initialize both arrays to all null strings */ title. = '' /* The array of keywords to search for among the book descriptors */ keyword.1 = 'earth' ; keyword.2 = 'computers' keyword.3 = 'life' ; keyword.4 = 'environment' /* The array of book titles, each having several descriptors */ title.1 = 'Saving Planet Earth'
title.1.1 = 'earth'title.1.2 = 'environment'title.1.3 = 'life'
title.2 = 'Computer Lifeforms'title.2.1 = 'life' title.2.2 = 'computers' title.2.3 = 'intelligence'
title.3 = 'Algorithmic Insanity' title.3.1 = 'computers' title.3.2 = 'algorithms' title.3.3 = 'programming'
(part I)
Example Script # 4 ( t II)
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 33/62
Example Script # 4… (part II)
arg weight /* Get number keyword matches required for retrieval */ say 'For weight of' weight 'retrieved titles are:' /* Output header */ do j = 1 while title.j <> '' /* Look at each book */
count = 0
do k = 1 while keyword.k <> '' /* Inspect its keywords */
do l = 1 while title.j.l <> '' /* Compute its weight */ if keyword.k = title.j.l then count = count + 1
end end if count >= weight then /* Display titles matching the criteria */
say title.j end
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 34/62
Discussion
• Array keyword. is a looku p table or l is t • key/value pairs like Perl or Berkeley DB
• Array title. is a t ree
• Trees can be balanced or not
DO I = 1 TO n BY m WHILE condition FOR xDO UNTIL … DO FOREVERDO n
IF condition THEN DO. . .END
ELSE DO. . .
END
Enclose multiple statementswithin a DO END pair
DO
IF
Create Any Data Structure With Rexx Arrays :
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 35/62
Create Any Data Structure With Rexx Arrays : Element 1 Element 2 Element 3 A Simple List
or Look-up Table Key-value Pairs
Key 1 Value 1 Key 2 Value 2 Key 3 Value 3 Key 4 Value 4
Balanced Tree Un-Balanced Tree
b.1b.1.1b.1.2
b.2b.2.1b.2.2
b.3b.3.1
b.3.2
b.1b.1.1
b.2
b.2.1b.2.2b.2.3
b.3b.4
b.1b.1.1
b.1.1.1b.1.1.2
b.2b.2.1b.2.2
b.2.3b.3
b3.1b.3.1.1
b.3.1.1.1 A Multi-level Tree
(unbalanced) Also: linked list, doubly
linked list, stack, queue,dequeue, etc...
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 36/62
Example-- Creating a Linked Lis t list.0 = HEAD ; list.0.next = 1 /* Define linked list. */list.1 = 'a' ; list.1.next = 2 /* You could also */list.2 = 'b' ; list.2.next = 3 /* create it */list.3 = TAIL ; list.3.next = TAIL /* dynamically. */
call display_linked_list /* Display the linked list */
list.99 = 'after a, before b' /* Add new item in list */list.99.next = 2 /* Point new item to next */list.1.next = 99 /* Point to the new item */
call display_linked_list /* Display the linked list */exit
display_linked_list: /* Displays the linked list*/sub = 0do while list.sub.next <> TAIL
say 'Element:' list.subsub = list.sub.next
end return
Wh R V Oth
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 37/62
For a language that “lacks data structures,”
Rexx sure has a lot of them!
Power thru Simpl ic i ty !
Why Rexx Vs Other Scripting Languages ?
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 38/62
IV. More abou t Rexx
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 39/62
Rexx Standards
TRL-2
ANSI
• 8 of 9 free Rexx interpreters adhere to TRL-2• ANSI adds little beyond TRL-2• Most Rexxes offer extensions
• Extensions offer OS-specific stuff and other niceties
Extensions
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 40/62
Rexx Standards
1990
Early
90s
TRL-2 SAA
1996
ANSI
4.00 5.00LanguageLevel
TRL-1
3.50
1985
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 41/62
The Evolution of Rexx
Standard or “Classic” Rexx
Object-oriented Rexx
NetRexx(for Java
environments)
Mid 1990s Early 1980s
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 42/62
Windows CE BRexxPalm OS Rexx for Palm OSSymbian / EPOC32 Regina
PocketDOSXTMothers BRexx
+ Faster
+ Integrates with native services
+ Integrates with...+ DOS Services+ DOS Applications
+ Many DOS appsinstantly availablewithout any changes
Native DOS Emulation
Rexx on Handhelds
Interpreter: Interpreter:
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 43/62
How DOS Emulation Works
PC Hardware Native operating system
Rexx Scripts Rexx Interpreter
DOS Operating System DOS Emulator
Each layer runs on topof the one
below it
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 44/62
Classic Rexx
Object-Oriented Rexx Means…
Classes and Methods PLUS
Inheritance & Derivation
Encapsulation
Abstraction
Polymorphism
Huge Class Library
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 45/62
ObjectRexx
Object Rexx Adds to Classic Rexx . . .
Complete ObjectOrientation
New Instructions
More Functions New Operators
Built-in Objects,Special Variables,many other features
Classes andMethods
And Much More
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 46/62
NetRexx • A “Rexx-like” language
• Brings Rexx ease of use to Java environment
• NetRexx scripts use Java classes
• Script:• Classes for use by Java• Applets• Applications• Servlets• Java Beans (EJBs)• Client & server sides both
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 47/62
Classic Rexx
NetRexx Goes Beyond Classic Rexx…
Changed and Extended with . . .
New instructions
Data typing (“types”)
Indexed strings
Special names
Object orientation
Special methods
… and much more …
Java environment integration
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 48/62
Translate NetRexx sourceinto a Java program
Developing and Running NetRexx Scripts
Run
Source scriptEg: hello.nrx
To translate, compile and run in one step enter: nrc -run hel lo
Java fileEg: hello.java
Compile Java into bytecode
Class fileEg: hello.class
NetRexx interprets and/or compiles. Can generate commented,formatted Java code. Runs under JVM or stand-alone.
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 49/62
V. More Rexx Features
How Rexx
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 50/62
-- Built-in Functions
-- Functions you develop
-- Subroutines
-- Extensions and
Function Libraries
-- Operating System Commands
-- Commands to other environments
-- External Programs
-- API Interfaces to external features
-- API into Rexx
Supports Modularity InternalRoutines
Modularity
ExternalResources
String Processing Operations
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 51/62
g g p abc + abc abcabc Concatenation
Joins two or more strings abcabc
abc abc
Bifurcation
Splits a string
abcabc Parsing
Scans and analyzes a string, may split it intoits constituent components
abcdef Pattern Matching
Identifies patterns in strings
Parse Count = 2
Find “def”
P i O ti
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 52/62
Parsing Operations
Separate by wordsBy Words
abc abc abc
Separate , using , commas By Pattern
By NumericPattern
Columns: 1 5 9
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 53/62
The Two I/O Modes
linein lineout
lines
Character-oriented
Process one character at a time
charin charout chars
+ More portable + Reads “special” characters
Line-oriented
Process one line at a time
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 54/62
QUEUE
The Stack is both a Stack and a Queue PULL,
PARSE PULL PUSH
Rexx‟s Stack is a generalized communications mechanism
Rexx Supports Recursion
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 55/62
pp
CallScript X
End TestFufilled ?
Script X
Yes
No
HowRecursionWorks
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 56/62
Tip – Steps to Good Programming Style
Spacing & indentation Good variable names
Limit Nesting Comments
Structured Code Modularity
Error checking Ect !
Capitalization
D b i O ti
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 57/62
Debugging Options
SAY Instruction TRACE Instructionin batch mode Interactive TRACE
+ Quick, informal+ Great for simple problems+ Requires changing code
(adding SAY instructions) + Resolves challenging problems+ Allows real-time code tests+ Programmer-directed
interaction resolves problems+ Quick & easy, but powerful
+ Batch script trace+ Can set trace level based on user input+ Many trace settings available+ Good for “paperanalysis” of a problem
C diti / E ti T i
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 58/62
signal on condi t ion name label_name
Condition / Exception Trapping
label_name:
…code of the main routine...
…code of the error handling routine...
Conditions: error, failure, halt, novalue, notready, syntax, lostdigits
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 59/62
VI. Conclusions
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 60/62
Conclusions
• Free & open source languages have taken over
• Scripting is the “quiet revolution”
• Rexx offers “Power through Simplicity”
• Useful addition to your toolbox
Resources
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 61/62
Resources Find everyth ing at www.RexxInfo.org
-- download Rexx-- download tools
-- tutorials, articles, how-to‟s -- reference materials
Rexx Programmer’s Reference at Amazonwww.amazon.com/rexx
7/14/2019 Rexx Overview
http://slidepdf.com/reader/full/rexx-overview 62/62
?
? ?
? questions...
? ?