Rexx – Variables ”; Previous Next In Rexx, all variables are bound with the ‘=’ statement. Variable names are sometimes referred to as symbols. They may be composed of Letters, Digits, and Characters such as ‘. ! ? _’. A variable name you create must not begin with a digit or a period. A simple variable name does not include a period. A variable name that includes a period is called a compound variable and represents an array or table. The following are the basic types of variables in Rexx which were also explained in the previous chapter − Integers − This is used to represent an integer or a float. An example for this is 10. Big integers − This represents a large integer value. Decimal − A decimal value is a string of numerics that contains a decimal point but no exponent identifier. Float − A float value is a string that represents a number in the scientific notation. String − A series of characters defines a string in Rexx. Different Types of Variable Functions In this section, we will discuss regarding the various functions a variable can perform. Variable Declarations The general syntax of defining a variable is shown as follows − var-name = var-value where var-name − This is the name of the variable. var-value − This is the value bound to the variable. The following program is an example of the variable declaration − Example Live Demo /* Main program */ X = 40 Y = 50 Result = X + Y say Result In the above example, we have 2 variables, one is X which is bound to the value 40 and the next is Y which is bound to the value of 50. Another variable called Result is bound to the addition of X and Y. The output of the above program will be as follows − 90 Naming Variables Variable names are sometimes referred to as symbols. They may be composed of Letters, Digits, and Characters such as ‘. ! ? _’ . A variable name you create must not begin with a digit or period. If a variable has not yet been assigned a value, it is referred to as uninitialized. The value of an uninitialized variable is the name of the variable itself in uppercase letters. An example of an unassigned variable is as follows − Example Live Demo /* Main program */ unassignedvalue say unassignedvalue If you run the above program you will get the following output − UNASSIGNEDVALUE sh: UNASSIGNEDVALUE: command not found 2 *-* unassignedvalue >>> “UNASSIGNEDVALUE” +++ “RC(127)” Variables can be assigned values more than once. The below program shows how the value of X can be assigned a value multiple times. Example Live Demo /* Main program */ X = 40 X = 50 say X The output of the above program will be as follows − 50 Printing Variables The values of variables are printed using the say command. Following is an example of printing a variety number of variables. Example Live Demo /* Main program */ X = 40 /* Display an Integer */ say X Y = 50.5 /* Display a Float */ say Y Z = “hello” /* Display a string */ say Z The output of the above program will be as follows − 40 50.5 hello Print Page Previous Next Advertisements ”;
Category: rexx
Rexx – Basic Syntax
Rexx – Basic Syntax ”; Previous Next In order to understand the basic syntax of Rexx, let us first look at a simple Hello World program. Example Live Demo /* Main program */ say “Hello World” One can see how simple the hello world program is. It is a simple script line which is used to execute the Hello World program. The following things need to be noted about the above program − The say command is used to output a value to the console. The /* */ is used for comments in Rexx. The output of the above program will be − Hello World General Form of a Statement In Rexx, let’s see a general form of a program. Take a look at the following example. Live Demo /* Main program */ say add(5,6) exit add: parse arg a,b return a + b The output of the above program will be − 11 Let’s go through what we have understood from the above program − Add is a function defined to add 2 numbers. In the main program, the values of 5 and 6 is used as parameters to the add function. The exit keyword is used to exit from the main program. This is used to differentiate the main program from the add function. The add function is differentiated with the ‘:’ symbol. The parse statement is used to parse the incoming arguments. Finally, the return statement is used to return the sum of the numeric values. Subroutines and Functions In Rexx, the code is normally divided into subroutines and functions. Subroutines and functions are used to differentiate the code into different logical units. The key difference between subroutines and functions is that functions return a value whereas subroutines don’t. Below is a key difference example between a subroutine and a function for an addition implementation − Function Implementation /* Main program */ say add(5,6) exit add: parse arg a,b return a + b Subroutine Implementation /* Main program */ add(5,6) exit add: parse arg a,b say a + b The output of both the programs will be the value 11. Executing Commands Rexx can be used as a control language for a variety of command-based systems. The way that Rexx executes commands in these systems is as follows. When Rexx encounters a program line which is neither an instruction nor an assignment, it treats that line as a string expression which is to be evaluated and then passed to the environment. An example is as follows − Example Live Demo /* Main program */ parse arg command command “file1” command “file2” command “file3″ exit Each of the three similar lines in this program is a string expression which adds the name of a file (contained in the string constants) to the name of a command (given as a parameter). The resulting string is passed to the environment to be executed as a command. When the command has finished, the variable “rc” is set to the exit code of the command. The output of the above program is as follows − sh: file1: command not found 3 *-* command “file1″ >>> ” file1″ +++ “RC(127)” sh: file2: command not found 4 *-* command “file2″ >>> ” file2″ +++ “RC(127)” sh: file3: command not found 5 *-* command “file3″ >>> ” file3″ +++ “RC(127)” Keywords in Rexx The free syntax of REXX implies that some symbols are reserved for the language processor”s use in certain contexts. Within particular instructions, some symbols may be reserved to separate the parts of the instruction. These symbols are referred to as keywords. Examples of REXX keywords are the WHILE in a DO instruction, and the THEN (which acts as a clause terminator in this case) following an IF or WHEN clause. Apart from these cases, only simple symbols that are the first token in a clause and that are not followed by an “=” or “:” are checked to see if they are instruction keywords. You can use the symbols freely elsewhere in clauses without their being taken to be keywords. Comments in Rexx Comments are used to document your code. Single line comments are identified by using the /* */ at any position in the line. An example is as follows − /* Main program */ /* Call the add function */ add(5,6) /* Exit the main program */ exit add: /* Parse the arguments passed to the add function */ parse arg a,b /* Display the added numeric values */ say a + b Comments can also be written in between a code line as shown in the following program − Live Demo /* Main program */ /* Call the add function */ add(5,6) /* Exit the main program */ exit add: parse /* Parse the arguments passed to the add function */ arg a,b /* Display the added numeric values */ say a + b The output of the above program will be − 11 You can also have multiple lines in a comment as shown in the following program − Live Demo /* Main program The below program is used to add numbers Call the add function */ add(5,6) exit add: parse arg a,b say a + b The output of the above program will be − 11 Print Page Previous Next Advertisements ”;
Rexx – Useful Resources
Rexx – Useful Resources ”; Previous Next The following resources contain additional information on Rexx. Please use them to get more in-depth knowledge on this. Useful Links on Rexx Rexx Programming − Official Home Page Rexx Wiki − Wikipedia Reference for Rexx. Useful Books on Rexx To enlist your site on this page, please drop an email to [email protected] Print Page Previous Next Advertisements ”;
Rexx – Discussion
Discuss Rexx ”; Previous Next 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. Print Page Previous Next Advertisements ”;
Rexx – Best Programming Practices ”; Previous Next Every programmer wants their program to be the best when it comes to quality and efficiency. The following are some of the best programming practices or hints when writing Rexx programs which can help one achieve these goals. Hint 1 Use the address command before you issue any command to the operating system or command prompt. This will help you get the address space beforehand in memory and cause your program to run more efficiently. An example of the address command is shown below. Example /* Main program */ address system dir The output of the command is as follows, but it could vary from system to system. Volume in drive H is Apps Volume Serial Number is 8E66-AC3D Directory of H: 06/30/2016 01:28 AM <DIR> Apps 07/05/2016 03:40 AM 463 main.class 07/07/2016 01:30 AM 46 main.nrx 07/07/2016 01:42 AM 38 main.rexx 3 File(s) 547 bytes Dir(s) 313,085,173,760 bytes free Hint 2 Ensure all commands to the operating system are in upper case and in quotes wherever possible. An example for the same is shown below. Example /* Main program */ options arexx_bifs say chdir(”REXXML100”) say directory() When we run the above program, we will get the following result. 0 D:rexxxml100 Hint 3 Avoid creating big comment blocks as shown in the following program. Example /******/ /* */ /* */ /* */ /******/ /* Main program */ address system dir Hint 4 Use the Parse statement to assign default values. An example for the same is shown below. Example parse value 0 1 with a, b Hint 5 Use the “Left(var1,2)” statement wherever possible instead of the “substr(var1,1,2)” statement. Hint 6 Use the “Right(var1,2)” statement wherever possible instead of the “substr(var1,length(var1),2)” statement. Print Page Previous Next Advertisements ”;
Rexx – Performance
Rexx – Performance ”; Previous Next One of the key aspects of any programming language is the performance of the application. Special practices need to be taken care of to ensure that the application’s performance is not hampered. Let’s look at some of the considerations described in steps for better understanding − Step 1 − Try to reduce the number of instructions – In Rexx each instruction carries an overhead. So try to reduce the number of instructions in your program. An example of instructions that can be redesigned is shown below. Instead of using multiple if else statements one can use the parse statement. So like in the following program, instead of having an if condition for each value, and getting the value of word1, word2, word3 and word4, use the parse statement. /* Main program */ parse value ”This is a Tutorial” with word1 word2 word3 word4 say “””word1″”” say “””word2″”” say “””word3″”” say “””word4″”” Step 2 − Try to combine multiple statements into one statement. An example is shown below. Suppose if you had the following code which did the assignment for – a and b and passed it to a method called proc. do i = 1 to 100 a = 0 b = 1 call proc a,b end You can easily replace the above given code with the following code using the parse statement. do i = 1 for 100 parse value 0 1 with a, b, call proc a,b end Step 3 − Try to replace the do..to loop with the do..for loop wherever possible. This is normally recommended when the control variable is being iterated through a loop. /* Main program */ do i = 1 to 10 say i end The above program should be replaced by the following program. /* Main program */ do i = 1 for 10 say i end Step 4 − If possible, remove the for condition from a do loop as shown in the following program. If the control variable is not required, then just put the end value in the do loop as shown below. /* Main program */ do 10 say hello end Step 5 − In a select clause, whatever u feel is the best condition which will be evaluated needs to put first in the when clause. So in the following example, if we know that 1 is the most frequent option, we put the when 1 clause as the first clause in the select statement. /* Main program */ select when 1 then say”1” when 2 then say”2” otherwise say ”3” end Print Page Previous Next Advertisements ”;
Rexx – Web Programming
Rexx – Web Programming ”; Previous Next Rexx has the facility to work with web servers as well. The most common being the apache web server. In order to use Rexxw with the Apache web server, you need to first download the Rexx modules from the following link − https://sourceforge.net/projects/modrexx/?source=typ_redirect Once done, make sure to add the mod Rexx modules to the class path. The following lines need to be added and modified to the Apache configuration file. The following lines need to be added to the end of the appropriate − httpd.conf LoadModule list. LoadModule rexx_module modules/mod_rexx.dll The following lines should be added at the end of the http.conf file. AddType application/x-httpd-rexx-script .rex .rexx AddType application/x-httpd-rexx-rsp .rsp Add these for REXX Server Page support RexxRspCompiler “c:/Program Files/Apache Group/Apache2/bin/rspcomp.rex” Once the above changes have been made, you need to shut down and restart your apache web server. The above lines also allow you to have Rexx based server pages just like Java server pages. You can add the Rexx code directly to the html pages. An example is shown below − <p>The current date and time is <?rexx /* Inserting the rexx statement */ say date() time() ?> </p> When a Rexx based server page is run, the following things are carried out − First a temporary file is created. Then the Rexx Server compiler compiles the file into a Rexx program and places it in the temporary file. The next step is to actually run the Rexx program. Finally, the temporary file is removed. Print Page Previous Next Advertisements ”;
Rexx – Reginald
Rexx – Reginald ”; Previous Next Reginald is another Rexx interpreter which was developed by Jeff Glantt and has some customizations on how Rexx programs can be run. In this section, we will see how to get Reginald setup and run a few Rexx programs in it. Environment Setup The first step is the environment setup which is to download the Reginald files. This can be done from the following website link − http://www.manmrk.net/tutorials/rexx/Reginald/win32/rxusrw32.htm Once the download is complete and you launch the installer, the next screen will allow you to choose the install location. Click the Install button to proceed. Once complete, we can now start to run one sample program in the Reginald interpreter. Create a simple program as shown below. /* Main program */ say ”Hello” Then run the following command − RxLaunch.exe main.rexx You will then get the following output. This program will now be running in the Reginald interpreter. Other Functions Available Apart from the normal Rexx commands, Reginald had some specific commands that are tailor-made for the Windows operating system. DriveMap is one such command − DriveMap This function gives information on the drive. Syntax − Drivemap(,options) Parameters − Options − These are a list of keywords which can be used to get various information on the drives of the local computer. Return Value A string value which has information on the drive. Example − /* Main program */ say ”Drives on system : ” DriveMap(,”FIXED”) If the above program is run, you will get the following output. This output depends from system to system. List of disk drives : C: D: Print Page Previous Next Advertisements ”;
Rexx – Quick Guide
Rexx – Quick Guide ”; Previous Next Rexx – Overview 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 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 www.oorexx.org Rexx – Environment 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 2 GB RAM (recommended) Disk Space No minimum requirement. Preferably to have enough storage to store the programs which will be created using Rexx. Operating System Version Rexx can be installed on Windows, Ubuntu/Debian, Mac OS X. Downloading Rexx To download Rexx, you should use the following URL − https://www.oorexx.org/download.html 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. Rexx – Installation 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. Step 3 − Click on the I Agree button to proceed. Step 4 − Accept the default components and then click on the next button. 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. 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. 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. 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. Step 13 − Click on the Finish button to complete the installation. Rexx – Installation of Plugin-Ins In this chapter, we will discuss on how to install plug-ins on popular IDE’s (Integrated Development Environment). Rexx as a programming language is also available in popular IDE’s such as Eclipse. Let’s look at how we can get the required plugin’s in these IDE’s, so that you have more choices in working with Rexx. Installation in Eclipse To make a trouble-free installation of Rexx in Eclipse, you will need to adhere to the following steps. Step 1 − Open Eclipse and click on the Menu item, Help → Eclipse Marketplace as shown in the following screenshot. Step 2 − In the next dialog box, enter Rexx in the search criteria and click on the search button. Once done, click the Install button. Step 3 − Click on the Confirm button to further continue with the features installation. Step 4 − Eclipse will then download the necessary files to start off with the installation. Once done, Eclipse will ask for accepting the license agreements. Click on accepting the license agreements and then click on the Finish button as shown in the following screenshot. Eclipse will then start installing the software in the background. Step 5 − You will probably get a security warning (as shown in the following screenshot). Click on the OK button to proceed. Step 6 − You will be prompted to restart Eclipse once the updates are installed. Click Yes to restart Eclipse. Rexx – Basic Syntax In order to understand the basic syntax of Rexx, let us first look at a simple Hello World
Rexx – Graphical User Interface ”; Previous Next In order to use the graphic user interfaces available in Rexx, one needs to use 2 packages, one is called ActiveTcl and the other is the Rexxtk package. Along with these 2 packages, one can design normal forms which can have buttons and other controls on the forms. Environment Setup The first thing to do is the environment setup. Let’s go through the following steps to have the environment in place. Step 1 − Download the Activetcl package from the following website − https://www.activestate.com/activetcl Step 2 − The next step is to start the installation of ActiveTCl. Click on the Next button on the screen to proceed. Step 3 − Accept the license Agreement and click on the Next button. Step 4 − Choose a location for the installation and click on the next button. Step 5 − Choose a location for the installation of the demo’s and click on the Next button. Step 6 − Click on the Next button to proceed with the installation. Step 7 − Click on the Finish button to complete the installation. Step 8 − The next step is to download the Rexxtk software from the following link − https://sourceforge.net/projects/rexxtk/ Step 9 − Double click the installer file from the link in the previous step to start the installation. Click on the next button to proceed. Step 10 − In the next screen, click on the Yes button to agree to the License Agreement. Step 11 − In the next screen, choose the location for the installation and click on the Next button. Step 12 − Choose the Program folder location and click on the next button. Once the installation is complete, we can now start with programming the GUI’s in Rexx. Basic Program Let’s see how we can design a simple basic program with Rexx in a graphical user interface format. Example /* Main program */ call RxFuncAdd ”TkLoadFuncs”,”rexxtk”,”TkLoadFuncs” call TkLoadFuncs do forever interpret ”Call” TkWait() end call TkDropFuncs exit 0 The following things need to be noted about the above program − The Rexxtk library and all of its functions are loaded using the RxFuncAdd command. The do forever loop will keep the window open and will wait for the user input. Once the user input is detected, the program will exit. When the above program is executed, you will get the following output. Creating Menus Menus are created with the help of the TkMenu and TkAdd functions. The syntax of these functions are given below. Syntax TkMenu(widgetname,options,0) Parameters Widgetname − A name to give to the menu. Options can be anyone of the following − selectcolor − if checkboxes or radio buttons are used as menu options, then this option specifies the color to choose when any menu option is selected. tearoff − This option is used for adding sub menus to the main menu. title − The string that needs to be used to give the window a title. Return Value A handle to the menu created. Example /* Main program */ call RxFuncAdd ”TkLoadFuncs”,”rexxtk”,”TkLoadFuncs” call TkLoadFuncs menubar = TkMenu(”.m1”) filemenu = TkMenu(”.m1.file”,”-tearoff”, 0) call TkAdd menubar, ”cascade”, ”-label”, ”File”, ”-menu”, filemenu call TkAdd filemenu, ”command”, ”-label”, ”Open…”, ”-rexx”, ”getfile” call TkConfig ”.”, ”-menu”, menubar do forever interpret ”Call” TkWait() end call TkDropFuncs exit 0 The following things need to be noted about the above program − The menubar is created using the TkMenu function. The ‘tearoff’ parameter means that we need to create sub menus which is going to be attached to the main menu. We then add 2 menu options called File and Open using the TkAdd function. When the above program is executed, you will get the following output. Print Page Previous Next Advertisements ”;