R A T F O R RT-11 VERSION RATional FORtran to Fortran Translator Version 1.0 26-Mar-1980 Gary M. Selzer Princeton Gamma-Tech, Inc. P.O. Box 641 Princeton, N.J. 08540 RATFOR PAGE 2 Acknowledgement ACKNOWLEDGEMENT Ratfor was written by Brian W. Kernighan and P.J. Plauger and is presented in their book Software Tools (Addison-Wesley, 1976). This version of Ratfor was modified from a version made available by Brian W. Kernighan, P.J. Plauger, and Bell Laboratories. INTRODUCTION Ratfor (for "RATional FORtran") is an extension of Fortran designed to facilitate the writing of programs that are logically correct, well-structured, easy to read and understand, and easy to modify. This is accomplished by providing a basic set of control structures which allow straightforward expresson of program logic, and by improving the syntax and appearance of Fortran. Ratfor is implemented as a Fortran preprocessor - that is, Ratfor programs are processed into Fortran source by a program called a "translator". Ratfor programs are inherently portable since they are translated into ANSI Fortran. Also, at least one version of Ratfor is itself entirely written in Ratfor so it itself is portable. A complete description of Ratfor, and many examples of its use, may be found in the text Software Tools, by Kernighan and Plauger. USING RATFOR Ratfor is executed by running file RATFOR.SAV. An input command string of the form dv1:fname1.ftype1=dv4:fname4.ftype4 must then be provided. Both devices dv1: and dv4: default to DK: if not specified. The default input filetype (ftype4) is .RFR; the default output filetype (ftype1) is .FOR. All included files must have filetype .RFI and be on the specified or defaulted input device dv4:. During execution Ratfor types the full file specification of any file it is attempting to open so all default assumptions about devices and filetypes are made explicit. Ratfor may be executed from an indirect command file, in which case the input command is obtained from the indirect command file. Ratfor differs from Fortran in that it exits after executing the first command instead of reprompting with a "*" and waiting for a new command string. Therefore, the usual "^C" is not necessary to return to RT-11 after execution. Normally a Fortran compile step will be necessary after Ratfor completes execution. Teco program RATFOR.TEC is provided as one way of conveniently generating and executing an indirect command of standard form to perform both processing steps. RATFOR.TEC RATFOR PAGE 3 Using Ratfor simply replaces a specified file name into a template indirect command string and executes the file. To execute RATFOR.TEC type ED/EXE:fname RATFOR. (RT command SET EDI TECO must be in effect for this to work.) The temporary indirect command COM.COM will then be generated and executed. To modifiy the file generated (to change switches, etc.) it is necessary to edit file RATFOR.TEC. A listing of RATFOR.TEC is shown below: ! RATFOR.TEC - GENERATE AND EXECUTE RATFOR COMMAND FOR SINGLE FILE. ! HX1HK ! Stash away specified file name. ! @I\! COM.COM : (RATFOR -> FORTRAN -> OBJECT) COMMAND FILE. R RATFOR ! ..... These lines ! = ! ..... constitute the template indirect ! R FORTRA ! ..... command file ! ,=/W ! ..... which may be ! ^C ! ..... modified. ! \ J<@S\\;-7DG1> ! Replace with specified name. ! @EW\COM.COM\@EG\@COM\ ! Write file COM.COM and execute it. ! There are 2 levels of error reporting, fatal errors and warnings. When a fatal error is encountered Ratfor types an explanatory message on the console terminal and quits. A warning (syntax error and the like) is typed on the console and included into the output file to mark the spot where the error was detected. RATFOR EXTENSIONS The left and right braces {} used to delimit compound statements are problematical on many systems so Ratfor provides the synonyms $( and $). In particular, in RT-11 both the editor and TECO for some reason translate } to ESCAPE. New versions of TECO and EDIT have been generated which overcome this difficulty. There are 2 non-standard features of RT-11 FORTRAN IV which turn out be inaccessible from Ratfor due to language incompatibilities. These are octal and RAD50 constants. Octal constants cause problems for Ratfor since Ratfor uses the double quote as a text string delimiter. Therefor another character has to be chosen to indicate octal constants. The character chosen for this purpose is the backslash (\). The constant \77 therefore represents an octal 77 for Ratfor, and is used where one might use "77 in Fortran. The FORTRAN IV construction for RAD50 constants nRxxx causes problems since Ratfor processes all incoming text not enclosed between single or double quotes and performs transformations such as blank and tab removal and letter case switching. (Likewise, the Fortran construction nHxxx is also not acceptable as Ratfor input.) The solution is to specify all RAD50 constants in the RATFOR PAGE 4 Ratfor Extensions form "text"r where text is a string of valid RAD50 characters. This may be used wherever the the Fortran equivalent nRtext may appear in a Fortran program. MODIFICATIONS FOR RT11 VERSION OF RATFOR The following modifications were made to the distributed version of Ratfor to produce this RT11 version: 1. This version uses double buffered SYSLIB I/O for input and single buffered SYSLIB I/O for output. 2. Input is entered via a standard RT-11 command string. 3. Error reporting is tailored to the RT-11 environment. 4. Backslash is used to indicate octal constants. 5. The syntax "TEXT"r is used for RAD-50 constants. 6. The TAB character has been introduced into the generated output. 7. The generated FORTRAN output is indented to indicate control level. 8. Input and output character mappings are now done by table indexing rather than search. FILES PROVIDED ON THIS TAPE The following files are provided on this tape: README.DOC Short description of RT-11 version of Ratfor (This file). RATFOR.SAV RT-11 version of Ratfor. RATFOR.TEC TECO command file generator. RATFOR.RFR Ratfor sources not modified for RT-11 version. RATMOD.RFR Ratfor sources modified for RT-11 version. RATDEF.RFI Include file for symbolic constant definitions. RATCOM.RFI Include file for Ratfor commonblocks. RATSTK.RFI Include file for stack pointer common block. RATFOR.FOR Fortran bootstrap if needed. RATMOD.FOR ... RATFOR.OBJ Object corresponding to file RATFOR. RATMOD.OBJ Object corresponding to file RATMOD. RATFOR.LNK Indirect command file for linking Ratfor.