The NetRexx Tutorial
- Introduction to NetRexx
NetRexx Tutorial - Introduction to NetRexx


Introduction to NetRexx

Introduction

In this chapter I try to give a global overview of the NetRexx language, along with a bit of history and some information on how to install and run it, etc. Probably the most interesting part starts from the paragraph A Small Journey Around NetRexx, where I try to develop some small programs, purely with the aim of giving you a "feeling" for this language. You can happily jump straight to this section, and leave all the details for later.

History of Rexx and NetRexx

Rexx was conceived, designed and developed by Mike Cowlishaw of IBM UK. The original motivation was to replace the then (1979) inadequate IBM command language (JCL and EXEC2). The basic idea was to develop something similar to PL/I, but easier to use. During the last 25 years Rexx developped a large community of users, since IBM was/is shipping it as part of it's major Operating Systems (MVS, VM, OS/2). IBM estimates that there are about 6 millions of Rexx Programmers around the world.

NetRexx was again conceived, designed and developed by Mike Cowlishaw IBM Fellow, in 1996. The motivation is is to create a language easier and simpler than Java, but keeping Java's main advantages.

Like Rexx, NetRexx is a real general-purpose language, tuned for both scripting and application development.

Availability of NetRexx.

The latest versions of NetRexx are available on IBM's WEB site at the following URLs:

 
http://www.ibm.com/Technology/NetRexx/nrdown.htm
 

USA Server or at

 
http://www2.hursley.ibm.com/netrexx/nrdown.htm
 

UK Server

On those sites you will find the NetRexx toolkit and the NetRexx Language Reference document, written by Mike Cowlishaw.

The NetRexx documentation and software are distributed free of charge under the conditions of the IBM Employee-Written Software program.

NetRexx is distributed in 2 formats:

Installing NetRexx on your machine.

Prerequisites

In order to install and run NetRexx, you need to have already installed:

Installation

Installing NetRexx is an easy process. In a nutshell, you need to:

You should consult the URL

 
http://www2.hursley.ibm.com/netrexx/doc-nrinst.htm
 

for more information about the installation. In Appendix I you'll find some examples of installation.

Additional sources of documentation

You can find additional informations at the URLs:

 
http://www2.hursley.ibm.com/netrexx/nrlinks.htm
 

For a collection of applets and classes written in NetRexx look at:

 
http://www.multitask.com.au/netrexx/fac/
 

The NetRexx Mailing list archives are at:

 
http://ncc.hursley.ibm.com/majordomo/IBM-NETREXX/archives/
 

The IBM redbook devoted to NetRexx can be found at:

 
http://www.redbooks.ibm.com/SG242216/2216ht.htm
 

The IBM reference is SG24-2216-0.

A Small Journey Around NetRexx

In this section I present a series of small programs, with which we will increase functionality and complexity. With these examples, I want to give you the 'feel' of NetRexx. Of course, if you are an experienced REXX programmer, you can quickly skip this section and go to the next chapter.

The "Hello, world!" Program.

Here is an example of your first NetRexx program, which you can call 'hello.nrx'.

 
+----------------------------------------------------------------------+
| -- Our first NetRexx Program                                         |01
| --                                                                   |02
| say 'Hello World!'                                                   |03
| exit 0                                                               |04
+----------------------------------------------------------------------+
                                                               hello.nrx
Download the source for the hello.nrx example

The third line contains a print statement to your terminal. Note that you DO NOT need to put a semi-colon (';') at the end of a line. You need one only if you want to put two or more statements on the same line, like it would be for:

 
 say 'Hello World!'; exit 0
 

In the fourth line, the exit statement is not mandatory; this means you can even avoid writing it. But it is indeed good practice always to exit from a program with the exit instruction. Even better, exit also with a return code, as in exit 0.

To run your program you now need to type:

 
  java COM.ibm.netrexx.process.NetRexxC hello
 

If the compilation was successful, you can now run the program typing:

 
  java hello
 

Adding some variables

Suppose that you now want to add some variables in your program. An example:

 
+----------------------------------------------------------------------+
| -- another very simple NetRexx program                               |01
| --                                                                   |02
| month_name = 'December'              -- string                       |03
| no_of_days = 31                      -- number                       |04
| say 'The month of' month_name 'has' no_of_days 'days.'               |05
| exit 0                                                               |06
+----------------------------------------------------------------------+
                                                             simple1.nrx
Download the source for the simple1.nrx example

As you see, the variable assignment operation is a very easy one, in NetRexx. You just need to type:

 
  variable = value
 

You do NOT need to declare the variable before the assignment. The only important thing to remember is that ALL variables are treated as strings, so the value you want to associate with them MUST go between single quotes ( ' ). You might ask yourself: "Also numbers are treated as strings?". And, yes, also numbers are strings, so it is little wonder that the following example lines are perfectly equivalent:

 
 days = 31
 days = days + 1
 
 days = '31'
 days = days + '1'
 

Of course, as you have seen, you can avoid the ( ' ) marks when you deal with numeric quantities.

Asking Questions and Displaying the Result

If you want to make your first program a little more complex, the usual way is to ask a question. Here is the final result:

 
+----------------------------------------------------------------------+
| -- simple2.nrx                                                       |01
| -- ask a question and display the answer                             |02
| --                                                                   |03
| say 'How many days are in December?'                                 |04
| answ = ask                                                           |05
| say 'Your answer is' answ'.'                                         |06
| exit 0                                                               |07
+----------------------------------------------------------------------+
                                                             simple2.nrx
Download the source for the simple2.nrx example

The instruction that tells NetRexx to get the input from the keyboard and put it into the variable named 'answ' is:

 
answ = ask
 

Adding Choices

Well, as it is the program is not really useful: you can answer anything, even a string of characters, and the program blindly accepts the answer. To make the code a little more 'intelligent' we try to distinguish between a good and a bad answer. Here is how: The code:

 
+----------------------------------------------------------------------+
| -- simple3.nrx                                                       |01
| -- ask a question and check the answer                               |02
| --                                                                   |03
| say 'How many days are in December?'                                 |04
| answ = ask                                                           |05
| if answ = 31                                                         |06
|   then say 'Correct Answer.'                                         |07
|   else say 'Wrong Answer.'                                           |08
| exit 0                                                               |09
+----------------------------------------------------------------------+
                                                             simple3.nrx
Download the source for the simple3.nrx example

Guessing the correct answer

Now we want our program to ask another question, in a case where the first has been answered correctly. We allow the user to make mistakes with the second question. The program will continue until a correct answer is given (or the user gets fed-up and hits CNTRL-C!).

 
+----------------------------------------------------------------------+
| /* simple3.nrx                                                       |01
|  * ask a question and check the answer                               |02
|  */                                                                  |03
| correct_answ = 31                                                    |04
| loop forever                                                         |05
|   say 'How many days are in December?'                               |06
|   answ = ask                                                         |07
|   if answ = correct_answ                                             |08
|     then                                                             |09
|       do                                                             |10
|         say 'Correct.'                                               |11
|         leave                                                        |12
|       end                                                            |13
|     else say 'Wrong Answer. Try again.'                              |14
| end                                                                  |15
| exit 0                                                               |16
+----------------------------------------------------------------------+
                                                             simple4.nrx
Download the source for the simple4.nrx example

More than one correct answer

Suppose we now ask a question for which there is more than one correct answer. We need to get the answer from the user, and test it against a series of good answers. It can be done with this program:

 
+----------------------------------------------------------------------+
| /* simple5.nrx                                                       |01
|  * verify answer from a list                                         |02
|  */                                                                  |03
| good_answ = 'APRIL JUNE SEPTEMBER NOVEMBER'                          |04
| loop forever                                                         |05
|   say 'Tell me a month with 30 days.'                                |06
|   answ = ask                  -- get the input                       |07
|   parse answ answ .           -- only the 1st word                   |08
|   answ = answ.upper()         -- uppercase it                        |09
|   if good_answ.wordpos(answ) = 0                                     |10
|     then                                                             |11
|       do                                                             |12
|         say 'You said "'answ'". It is wrong.'                        |13
|         say 'Try again.'                                             |14
|       end                                                            |15
|     else                                                             |16
|       do                                                             |17
|         say 'Correct.'                                               |18
|         leave                                                        |19
|       end                                                            |20
| end                                                                  |21
| exit 0                                                               |22
+----------------------------------------------------------------------+
                                                             simple5.nrx
Download the source for the simple5.nrx example

There are several new things introduced. Let us look at them: line 4: Here we enter a loop from which we will never exit, (loop forever). This might seem dangerous, but is not. The instruction leave in line 19 gives us an escape path: the only way to exit the loop is to enter a good answer. lines 7,8,9: The instructions are meant to "grab the answer, get only the first world, and uppercase it". This will make life much easier later.

In fact, what parse answ answ . does is:

 
  user types               answ value
  ------------------------ ------------------------
  January                  JANUARY
  I don't know             I
  February                 FEBRUARY
  please, stop it!         PLEASE,
 

NOTE: The lines

 
   answ = ask                  -- get the input         
   parse answ answ .           -- only the 1st word                 
   answ = answ.upper()         -- uppercase it                      
 

can be written as:

 
   parse ask.upper() answ .    
 

which is the NetRexx equivalent for the Classical REXX:

 
   parse upper pull anws .
 

line 10: The instruction good_answ.wordpos(answ) is the key to the program's functioning. It says: Look in the list good_answ and try to find answ. If you find it, tell me its position. Otherwise, tell me 0. Thus, if the answer is wrong, we get 0, and we continue to loop. An alternative way to perform this task as follows:

 
+----------------------------------------------------------------------+
| /* simple6.nrx                                                       |01
|  * verify answer from a list                                         |02
|  */                                                                  |03
| good    = 0                                                          |04
| good[0] = 4                                                          |05
| good[1] = 'APRIL'                                                    |06
| good[2] = 'JUNE'                                                     |07
| good[3] = 'SEPTEMBER'                                                |08
| good[4] = 'NOVEMBER'                                                 |09
| loop forever                                                         |10
|   say 'Tell me a month with 30 days.'                                |11
|   answ = ask                  -- get the input                       |12
|   parse answ answ .           -- only the 1st word                   |13
|   answ = answ.upper()         -- uppercase it                        |14
|   found = 0                                                          |15
|   loop i = 1 to good[0]                                              |16
|     if good[i] <> answ then iterate                                  |17
|     found = 1                                                        |18
|     leave                                                            |19
|   end                                                                |20
|   if found = 0                                                       |21
|     then                                                             |22
|       do                                                             |23
|         say 'You said "'answ'". It is wrong.'                        |24
|         say 'Try again.'                                             |25
|       end                                                            |26
|     else                                                             |27
|       do                                                             |28
|         say 'Correct.'                                               |29
|         leave                                                        |30
|       end                                                            |31
| end                                                                  |32
| exit 0                                                               |33
+----------------------------------------------------------------------+
                                                             simple6.nrx
Download the source for the simple6.nrx example

In line 04 we initialise an ARRAY to a default value. The initialization practice is not needed, in a program so short as simple6.nrx; but it is a must in more complicated programs. This line tells NetRexx: "initialise any good[] array variable to 0."

Classical REXX users will remember the "standard" initialization of a STEM variable:

 
good. = 0
 

In lines 05-09, we define the values of good[] array. An ARRAY variable is an array of values, and usually (even if it is not mandatory) the 0 element (good[0]) contains the information "how many elements are there in this array?". Since there are four elements, good[0] is equal to 4. Here is another example of ARRAY:

 
variable      value
------------- ------------------------------------
line[0]       3
line[1]       Test line no 1
line[2]       Another one
line[3]       third line
 

If we then want to see if an answer is correct, we need to set a flag (found) to FALSE (0) and 'scan' the array until we find the right answer, when we set the flag to TRUE, and exit from the loop (line 14). Then, depending on the value of the flag, we display the appropriate answer as in the previous example. You may have noticed from the length of the two examples that as a rule of thumb it is easier to have data structures in the form of strings than in the form of STEMS Ñ at least when you have very simple entities such as those used in these examples.

More than one list

Suppose you want a program that shows the number of days in a particular month. Since we are lazy, we will not write the full month name, the three first letters are enough. In this case we need two lists: one containing the month names (month_list), and another containing, IN THE SAME ORDER, the number of days of the given month (days_list).

 
+----------------------------------------------------------------------+
| /* simple7.nrx                                                       |01
|  * use two lists                                                     |02
|  */                                                                  |03
| month_list = 'JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC'       |04
| days_list  = ' 31  28  31  30  31  30  31  31  30  31  30  31'       |05
| good = 0                                                             |06
| loop while good = 0                                                  |07
|   say 'Tell me a month (JAN, FEB, etc.)'                             |08
|   parse ask.upper() answ .                                           |09
|   if month_list.wordpos(answ) <> 0                                   |10
|     then good = 1                                                    |11
|     else say 'Wrong, Try again.'                                     |12
| end                                                                  |13
| days = days_list.word(month_list.wordpos(answ))                      |14
| say 'Month "'answ'" has' days 'days.'                                |15
| exit 0                                                               |16
+----------------------------------------------------------------------+
                                                             simple7.nrx
Download the source for the simple7.nrx example

Dealing with files (I)

In the previous example, the two variable month_list and days_list are long strings. In real life this kind of information is stored in files containing the data used by the program. A file example can be the following:

 
+---------------------------------------------------------+
|* This file contains the month list, with the number     |
|* of days corresponding.                                 |
|*                                                        |
|                                                         |
| January   31                                            |
| February  28                                            |
| March     31                                            |
| April     30                                            |
| May       31                                            |
| June      30                                            |
| July      31                                            |
| August    31                                            |
| September 30                                            |
| October   31                                            |
| November  30                                            |
| December  31                                            |
+---------------------------------------------------------+
                                                 month.list

To make the example a little more interesting, we have added comment lines (all lines starting with an asterisk ("*")) and blank lines. The following program reads the file month.list and counts the number of months, printing the total number of months and days in a year.

 
+----------------------------------------------------------------------+
| -- monthfile.nrx                                                     |01
| -- test file I/O                                                     |02
| --                                                                   |03
| infid = xfile('month.list')                                          |04
|                                                                      |05
| rc = infid.read()                                                    |06
| if rc <> 0 then                                                      |07
|   do                                                                 |08
|     say 'Error reading' infid.name'.'                                |09
|     exit 1                                                           |10
|   end                                                                |11
|                                                                      |12
| total  = 0                                                           |13
| monthl = ''                                                          |14
| loop i = 1 to infid.lines                                            |15
|   parse infid.line[i] month days .                                   |16
|   if month = '' then iterate                                         |17
|   if month.left(1) = '*' then iterate                                |18
|   monthl = monthl month                                              |19
|   total = total+days                                                 |20
| end                                                                  |21
|                                                                      |22
| say 'There are' monthl.words() 'months.'                             |23
| say 'For a total of' total 'days.'                                   |24
| exit 0                                                               |25
+----------------------------------------------------------------------+
                                                           monthfile.nrx
Download the source for the monthfile.nrx example

In line '06' we issue a read over the file. All the lines are moved into the STEM list and are ready to process. See below for more information about this instruction. Note line '07': if something is not right ( such as the file being non-existent ) we exit with an error message. It is always a GOOD IDEA to check return codes from operations that might otherwise disturb the correct functioning of the program. The skipping of the comment and blank lines is done in lines '17' and '18'. NOTE: The reading of the file was performed using some instructions:

 
 infid = xfile('month.list')  -- define the file
 rc = infid.read()            -- issue the read
 

those instructions are not part of the native NetRexx, but they are part of an extension package of this book. This extension package is called xfile and it should be installed in order to correctly run the example shown above. In a nutshell, you need to:

Look at the "Tools" section for more information about this subject. A tool is also available to compile all the "library" files in an easy way (look for xbuild).

"Real" Example no. 1

I don't know about you, but for me this story of months is becoming a bit tedious. I suggest trying a REAL program, which you might even want to write down (or copy from the repository) and use.

Write a tailored finger command.

The standard finger UNIX command is a good and simple example of a socket client-server application: a client application finger running on your local machine goes to query a server (which runs a fingerd daemon) who answers giving a list of the logged on people on the server machine itself.

We will write a simple finger client and will format the fingerd's output in a more compact form.

Finger output format

The output of the fingerd daemon is in the following format:

 
....................................................................
rsl3pm1 (201) finger @shift3.cern.ch
(... lines omitted...)
nahn     steven nahn           r31 1:00 Tue 09:01
rattaggi monica rattaggi       r37    5 Tue 09:56
blyth    simon blyth           r38  20: Mon 13:20
blyth    simon blyth           q90   3d Fri 12:21
(... lines omitted...)
rsl3pm1 (203) 
....................................................................
                                        finger command output sample

Here I just used the standard UNIX finger command, as it is available on any UNIX machine.

Note also that I just showed only few lines. Some systems might have hundreds of lines.

What we want is a more compact output format, which just shows the number of sessions each user has active, and a flag that shows if the inactivity time of a terminal session is less than an hour.

Also, we want to write a program that runs not only on UNIX, but also on WNT, W95, MAC (and I could continue) in a word, on any machine where NetRexx runs.

The full 'xfinger' code.

In the first lines we need some initialisation, like the program version, the author, and some constants, like the port for the finger daemon, and a Carriage Return - Line Feed sequence of characters, which are required by the simple fingerd protocol.

 
+----------------------------------------------------------------------+
| /* xfinger                                                           |01
|  */                                                                  |02
| VERSION         = 'v1r000'                                           |03
| AUTHOR          = 'P.A.Marchesini, ETHZ'                             |04
|                                                                      |05
| DEFAULT_PORT    = int 79;                                            |06
| CRLF = '\x0D\x0A'                                                    |07
+----------------------------------------------------------------------+

We now get the system we want to talk with. If the user doesn't give one, or he types -h or --help we give some help.

 
+----------------------------------------------------------------------+
| parse arg system                                                     |09
| if system = '-h' | system = '--help' | system = '' then              |10
|   do                                                                 |11
|     parse source . . myname'.'                                       |12
|     say myname 'version' VERSION '(c)' AUTHOR                        |13
|     say 'Purpose : sample implementation of a finger client.'        |14
|     say                                                              |15
|     say 'java xfinger SYSTEM'                                        |16
|     say                                                              |17
|     exit 1;                                                          |18
|   end                                                                |19
+----------------------------------------------------------------------+

Now comes the "real" fun. We define a socket port (25) and we define it on the fingerd PORT (27). Since we need to transfer data over the link, we have to define an INPUT (28) and OUTPUT (29) communication.

 
+----------------------------------------------------------------------+
| -- issue the client socket command                                   |21
| --                                                                   |22
| out = 0                                                              |23
| j   = 0                                                              |24
| s = Socket null;                                                     |25
| do                                                                   |26
|   s = Socket(system, DEFAULT_PORT);                                  |27
|   sin   = DataInputStream(s.getInputStream());                       |28
|   sout  = PrintStream(s.getOutputStream());                          |29
|   line  = String                                                     |30
|   line  = crlf                           -- retrieve all entries     |31
|   sout.println(line)                     -- write msg                |32
|   loop forever                                                       |33
|     line = sin.readLine();                                           |34
|     if (line = null) then do                                         |35
|       leave                                                          |36
|     end                                                              |37
|       j = j+1                                                        |38
|       out[j] = line                                                  |39
|     end                                                              |40
| catch e1=IOException                                                 |41
|   say 'ERROR:' e1'.'                                                 |42
| finally                                                              |43
|   do                                                                 |44
|     if (s \= null) then s.close()                                    |45
|   catch e2=IOException                                               |46
|     say 'ERROR:' e2'.'                                               |47
|   end                                                                |48
| end                                                                  |49
| out[0] = j                                                           |50
+----------------------------------------------------------------------+

Now comes a very important point:

If what you are looking for is just an equivalent of the UNIX(tm) finger command, then you're already done.

All you would need at this stage is to output the array out[] and, voila', you'd have your nice, working, finger client which runs on all the platforms we saw above, without recompiling!

But we want even more, so let's build a better output, as we discussed.

 
+----------------------------------------------------------------------+
| -- order the output, now                                             |52
| --                                                                   |53
| sessions = 0                                                         |54
| active   = '.'                                                       |55
| users = ''                                                           |56
| loop i = 2 to out[0]                       -- skip the first line    |57
|   parse out[i] userid . 35 quiet 40 .                                |58
|   if quiet = '' then                                                 |59
|     do                                                               |60
|       active[userid] = '*'                                           |61
|     end                                                              |62
|   if users.wordpos(userid) = 0 then                                  |63
|     do                                                               |64
|       users = users userid                                           |65
|     end                                                              |66
|   sessions[userid] = sessions[userid] + 1                            |67
| end                                                                  |68
+----------------------------------------------------------------------+

We define a list of users (initialised to the empty string (56)). We also assume that a user is inactive, and we initialize the active array to the inactive status (54). The first line is not interesting, so we loop over the lines starting from the second till the last one (57). We PARSE the line, getting the remote userid, and (after 35 characters) the activity flag (58).

If the flag is empty, than the user is active, so we set the active array to active ("*") for him (59-62). If it's the first time we encounter this user, we add him to the user list (63-66).

Finally, we increment the session counter for him (67).

We've now all the information we need. Let's print it on the screen.

 
+----------------------------------------------------------------------+
| -- display the result                                                |70
| --                                                                   |71
| oline = ''                                                           |72
| list = users                                                         |73
| loop while list <> ''                                                |74
|   parse list user list                                               |75
|                                                                      |76
|   item  = user'('sessions[user]','active[user]')'                    |77
|   oline = oline||item.left(14)                                       |78
|   if oline.length() > 80 then                                        |79
|     do                                                               |80
|       say oline                                                      |81
|       oline = ''                                                     |82
|     end                                                              |83
| end                                                                  |84
| if oline <> '' then say oline                                        |85
|                                                                      |86
| exit 0                                                               |87
+----------------------------------------------------------------------+
                                                             xfinger.nrx
Download the source for the xfinger.nrx example

We get the user list(73). We loop over it, analysing user by user (74-75). We generate an output line, and showing it on the screen when it's longer than 80 characters (77-84).

And finally that's a full output of the command we just created.

 
..................................
rsl3pm1(44) java xfinger shift3
fcot(1,.)     clarei(1,.)   blyth(11,.)   root(1,.)
palit(1,.)    marchesi(1,.) forconi(3,.)  shvorob(6,.)
tully(1,.)    tau(1,.)      braccini(1,.) xujg(2,.)
button(2,.)   filthaut(1,.) fisherp(2,.)  clare(2,.)
oulianov(2,.) pierim(1,.)   malgeril(1,.) gruenew(1,.)
fenyi(1,*)    barczyk(1,.)  graven(2,.)   dsciar(1,.)
passelev(1,.) choutko(2,.)  l3mc1(1,.)    clapoint(1,.)
lodovico(1,.) paus(2,.)     campanel(1,.) l3mc3(1,.)
despixv(1,.)  jessicah(1,.) dmigani(3,.)  lad(1,.)
................................

(NOTE: so few active people since it was taken at 2:00 AM 8-) )

Real example no. 2

We now write a simple Infix to Polish notation converter, with the purpose of writing a program capable to understand expression of the kind:

 
1 + 5*4 + abs(7-6*2)
 

and write, hopefully, the correct result.

A complete discussion of the problem can be found in KRUSE, 1987, p. 455.

 
 *** This section is: 
  
 *** and will be available in next releases

Translation from INFIX form to POLISH form.

 
+----------------------------------------------------------------------+
| -- method......: translate                                           |70
| -- purpose.....: convert an infix tokenized string to a Polish       |71
| --               Notation                                            |72
| --                                                                   |73
|   method translate(intk=Rexx) public static                          |74
|                                                                      |75
|     -- initialization                                                |76
|     --                                                               |77
|     valid_tokens = '+ - * / abs'                                     |78
|     stk = ''                     -- empty stack  (work)              |79
|     pol = ''                     -- output stack                     |80
|                                                                      |81
|     loop until intk = ''                                             |82
|       parse intk t intk                                              |83
|       select                                                         |84
|         when t = '(' then                                            |85
|           do                                                         |86
|             stk = t stk          -- push()                           |87
|           end                                                        |88
|         when t = ')' then                                            |89
|           do                                                         |90
|             parse stk t stk                                          |91
|             loop while t <> '('                                      |92
|               pol = pol t        -- output                           |93
|               parse stk t stk    -- pop()                            |94
|             end                                                      |95
|           end                                                        |96
|         when valid_tokens.wordpos(t) <> 0 then                       |97
|           do                                                         |98
|             loop forever                                             |99
|               if stk = '' then leave                                 |00
|               tk1 = stk.word(1)                                      |01
|               if tk1 = '(' then leave                                |02
|               if priority(tk1) < priority(t) then leave              |03
|               if priority(tk1) = priority(t) & priority(t) = 6       |04
|                  then leave                                          |05
|               parse stk x stk                                        |06
|               pol = pol x                                            |07
|             end                                                      |08
|             stk = t stk                                              |09
|           end                                                        |10
|         otherwise                                                    |11
|           do                                                         |12
|             pol = pol t                                              |13
|           end                                                        |14
|       end                                                            |15
|     end                                                              |16
|     loop while stk <> ''                                             |17
|       parse stk x stk                                                |18
|       pol = pol x                                                    |19
|     end                                                              |20
|     pol = pol.space()                                                |21
|     return pol                                                       |22
|                                                                      |23
+----------------------------------------------------------------------+
                                           xstring.nrx(Method:translate)
Download the complete source for the xstring.nrx library

Evaluation of Postfix expressions.

This is the evaluation part.

 
 *** This section is: 
  
 *** and will be available in next releases

 
+----------------------------------------------------------------------+
| -- method......: evalrpn                                             |36
| -- purpose.....: evaluates an RPN expression                         |37
| --                                                                   |38
|   method evalrpn(intk=Rexx,precision=Rexx) public static             |39
|                                                                      |40
|     -- initialization                                                |41
|     --                                                               |42
|     if precision = ''                                                |43
|       then precision = 9                                             |44
|     numeric digits precision                                         |45
|     stk = ''                      -- stack                           |46
|                                                                      |47
|     loop while intk <> ''                                            |48
|       parse intk tk intk                                             |49
|       select                                                         |50
|         when 'abs'.wordpos(tk) <> 0 then                             |51
|           do                                                         |52
|             parse stk p1 stk                                         |53
|             select                                                   |54
|               when tk = 'abs' then r = p1.abs()                      |55
|               otherwise NOP                                          |56
|             end                                                      |57
|             stk = r stk                                              |58
|           end                                                        |59
|         when '+ * - /'.wordpos(tk) <> 0 then                         |60
|           do                                                         |61
|             parse stk p2 p1 stk                                      |62
|             select                                                   |63
|               when tk = '+' then r = p1 + p2                         |64
|               when tk = '-' then r = p1 - p2                         |65
|               when tk = '*' then r = p1 * p2                         |66
|               when tk = '/' then r = p1 / p2                         |67
|               otherwise NOP                                          |68
|             end                                                      |69
|             stk = r stk                                              |70
|           end                                                        |71
|         otherwise                                                    |72
|           do                                                         |73
|             stk = tk stk                                             |74
|           end                                                        |75
|       end                                                            |76
|     end                                                              |77
|     stk = stk.space()                                                |78
|     return stk                                                       |79
|                                                                      |80
+----------------------------------------------------------------------+
                                             xstring.nrx(Method:evalrpn)
Download the complete source for the xstring.nrx library

Summary

Here is a resume' of what we have covered in this chapter:

 
Compiling and running a program (on any platform)
-------------------------------------------------
  java COM.ibm.netrexx.process.NetRexxC PROG
  java PROG
  - ex.: java COM.ibm.netrexx.process.NetRexxC hello
         java hello

 
 
 *** This section is: 
  
 *** and will be available in next releases


File: nr_5.html.

The contents of this WEB page are Copyright © 1997 by Pierantonio Marchesini / ETH Zurich.

Last update was done on 18 May 1998 21:47:35(GMT +2).