
AN ABSTRACT OF THE THESIS OF EDWARD BURLINGAME HILL for the MASTER OF SCIENCE (Name) (Degree) in MATHEMATICS presented on October 16, 1968 (Major) (Date) Title: A FORTRAN TO ALGOL TRANSLATOR Abstract approved: Harry E. Goheen FORTRAN is readily feasible to translation into ALGOL since they share many common features. Most of the features that are unique to FORTRAN can be translated by restricting them some- what. The translator will handle explicit declarations of each item in a block, compensate for the differences in various operators, compensate for the different storage techniques and provide a simple input /output scheme. Running test cases through the FORTRAN programs and through the translated ALGOL programs indicated that the ALGOL programs take longer to execute than their FORTRAN counterparts. A FORTRAN to ALGOL Translator by Edward Burlingame Hill A THESIS submitted to Oregon State University in partial fulfillment of the requirements for the degree of Master of Science June 1969 APPROVED: Professor of Ma matics /(J in charge of major Acting Chairman of the Department of thematics Dean of raduate School Date thesis is presented October 16, 1968 Typed by Gwendolyn Hansen for Edward Burlingame Hill ACKNOWLEDGEMENTS I would like to thank Professor H. E. Goheen for first pro- posing this translator and for his help and encouragement in the development of this thesis. I would also like to thank Professors D. D. Aufenkamp, F. H. Young and the Oregon Research Council for providing the grant which enabled me to write the translator. The 0S3 systems group deserves special thanks for the advice and help they have given me when I was programming the translator. I would also like to thank Peter and Karen Becker for proofreading the thesis. Finally, I would like to thank my parents for helping make it possible for me to take the time to finish this project. TABLE OF CONTENTS Pag e INTRODUCTION 1 ELEMENTS OF FORTRAN AND ALGOL LANGUAGES 5 Constants and Variables 6 Declarative Statements 9 Replacement and Manipulative Expressions 20 Control Statements 22 Function and Subroutine Subprograms 25 Library Subprograms 30 Input /Output 31 DESCRIPTION OF SUPPORT MODULES 35 ROLLS AND TABLES 46 PSEUDO- FORTRAN 50 EPILOGUE 53 BIBLIOGRAPHY 56 APPENDICES 57 Appendix 1. Test Cases 57 Appendix 2. Users Guide 78 Appendix 3, Flowcharts 87 Appendix 4. Program Listing 184 A FORTRAN TO ALGOL TRANSLATOR INTRODUCTION A translator is defined as a "routine for changing information from one representation or language into another." This translator accepts a source program written in FORTRAN for the Control Data Corporation's 3300 computer and translates the source program into an ALGOL source program for the same machine. This machine was chosen since Oregon State University owns the necessary compilers. The translator will enable an applications programmer to utilize programs and subroutines written in FORTRAN directly in his ALGOL programs without having to concern himself with their incompatibility. The translator handles the different methods in handling fixed -mode arithmetic, differences in real to integer conversion, differences in the method by which FORTRAN and ALGOL organize their data, and the necessity of explicitly declaring all the attributes of every variable at the head of each subprogram. A pseudo- FORTRAN language has been developed. Pseudo - FORTRAN relaxes many of the restrictions in FORTRAN and includes several features not found in FORTRAN. Of course, the translator removes the necessity of copying one's FORTRAN program into ALGOL for publication in those journals that use ALGOL as their publication language. 2 The program is written in COMPASS and is designed to be run on a Control Data Corporation 3300 computer. The required input/ output devices are a card reader and punch, a line printer and two disk files. The input to the program consists of a FORTRAN source deck subject to various restrictions. The source deck should start with a program card and end with a finis card. The output consists of listings of the FORTRAN source program and the ALGOL source program on the line printer, and, if desired, a listing of the ALGOL source program on some other output device. Any errors that the translator locates will be found in the FORTRAN listing. Before going into a brief description of how the translator works a few terms need to be defined. A roll is an array of informa- tion whose storage requirements vary, while a table is an array of information whose storage requirements are fixed. For example, a list of all the variables used in a program together with their attributes would be a roll, while a list of the FORTRAN reserved words would be a table. A push down list is a roll that is constructed and maintained so that the first item to be removed is the most recently stored item in the list. Such a list is used in analyzing arithmetic expressions. Push down lists are also called stacks. A symbol is the representation of something else by reason of 3 relationship, association, or convention. It could also be any element of the FORTRAN or ALGOL language. A character is a member of a set of elementary symbols. A character set usually contains the alphabet, the digits zero through nine, punctuation marks and any other symbols acceptable to a computer for reading, writing or storing. An attribute is any property associated with a symbol. A role indicator is a code assigned to a symbol to indicate some attribute of that symbol. An example would be the code 9 assigned to the variable I indicating that it is an integer subroutine parameter. Kind and type both refer to the attributes associated with a variable. Kind refers to whether a variable is simple or subscripted, while type refers to whether a variable is real, integer, character, or logical (boolean). A properly defined variable must have both a kind and a type attribute. The translator handles the FORTRAN program and subprograms as independent blocks surrounded by a single global block consisting of a BEGIN and an END statement. The subprograms are handled by procedures. The translator is divided into two passes called PASS 1 and PASS 2. PASS 1 prepares the FORTRAN program for PASS 2 by a. deleting comments and format statements, b. handling multiple returns by unconditional jumps to the end of the subprogram, 4 c. rearranging the order of the FORTRAN program so the subroutines preceed the main program, d. rearranging the order of the declarative statements so the data statement becomes the last declarative statement, e. handling the stop statement by means of an unconditional jump to the end of the FORTRAN program, f. preparing a roll containing the names of all the subprograms and the number of common elements in each subprogram. PASS 2 does the actual translation on a statement by statement basis and prints the ALGOL source deck. In general, PASS 2 reads a FORTRAN statement from logical unit 55, determines what type of statement it is and branches to the proper routine to process it. If the statement is declarative,the information is stored in various rolls. If it is not, the information is translated into an internal code and is stored on the program roll. When the end of a program or subprogram is indicated,the translator prints the attributes stored in the various tables and prints the inter- nal codes on the program roll as the appropriate ALGOL source code. The finis card serves as a signal to end the ALGOL program. Upon encountering this card, the translator closes the first block and prints out the end of program card. 5 ELEMENTS OF FORTRAN AND ALGOL LANGUAGES This chapter consists of a description of how the translator handles the various FORTRAN expressions. It also indicates where the various restrictions originate and why they were imposed. FORTRAN statements are divided into four classes. They are declarative, replacement, control, and input /output statements. Declarative statements assign attributes to variables, enter data, reserve storage, and overlay the various segments of the program. The translator supports the first feature without restriction, sup- ports the second and third features with restrictions and does not support the fourth feature. The second class of FORTRAN statements is the class of replacement statements. These statements incorporate expressions for manipulating the variables. Most manipulative statements are supported, some directly and some with the aid of a library of ALGOL subroutines. Those that are not supported will be flagged by an error message. The third class is control statements. These alter the sequence of program execution conditionally or unconditionally. All control statements are fully supported by the translator. The fourth class is input /output statements. These statements provide for the transfer of data from one part of memory to another 6 or from the computer to an external device and vice versa. A simple input /output scheme using the procedures Inreal and Outreal has been adopted for this translator. A comment card is a card which is to be ignored by the compiler. For the FORTRAN system is is denoted by a "c" in column one. The comment card allows the programmer to describe what steps the program is taking. These cards are printed in the source listing and are ignored by the compiler. Rather than store comment cards for later insertion into the ALGOL source program the trans- lator simply deletes them from the source deck, in all cases except the case of type logical cards. These cards are treated in FORTRAN as comment cards so that the FORTRAN program can be compiled with these cards in the deck without causing the FORTRAN compiler to produce a diagnostic. For the translator they are not comment cards.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages277 Page
-
File Size-