FLECS USER'S MANUAL University of Michigan Edition 25 November, 1975 Revised 18 August, 1980 This manual corresponds to version 22.7 of FLECS. (Revised September 10, 1974) Author: Terry Beyer Computing Center University of Oregon Eugene, Oregon 97409 Telephone: (503) 686-4416 Edited for MTS by: Gerald N. Cederquist Cooley Electronics Laboratory North Campus The University of Michigan Ann Arbor, Michigan 48109 Telephone: (313) 763-3092 Although care has been taken to ensure the correct functioning of the FLECS system, neither the author nor the editor nor the University of Oregon nor The University of Michigan shall be liable for any direct or indirect, incidental, consequential, or specific damages of any kind or from any cause whatsoever arising out of or in any way connected with the use or performance of the FLECS system or its documentation. This manual is in the public domain and may be altered or reproduced without the explicit permission of the author. Please communicate any errors, ambiguities, or omissions to the editor. Additional copies of this document are available from the editor. The editing of this manual for MTS was supported by the Office of Naval Research under contract N00014-75-C-0174. Acknowledgements ________________ The author is indebted to many people for assistance of one form or another during the course of this project. Mike Dunlap, Kevin McCoy, and Peter Moulton deserve special thanks for many helpful and fruitful discussions, suggestions, and encouragements. I am grateful to my wife, Kathleen, who assisted in many ways including shielding me from the harsh reality of JCL and 360 Assembly Language. Text preparation was adroitly accomplished by Marva VanNatta, Allyene Tom, Diane Lane, and Kathleen Beyer. This project was initiated while the author was working under a grant provided by the Office of Scientific and Scholarly Research of the Graduate School at the University of Oregon. Work on the project has also been supported in part by the Department of Computer Science and by the Computing Center of the University of Oregon. TABLE OF CONTENTS 1.0 INTRODUCTION ....................................... 1 2.0 RETENTION OF FORTRAN FEATURES ...................... 1 3.0 CORRELATION OF FLECS AND FORTRAN SOURCES ........... 2 4.0 STRUCTURED STATEMENTS .............................. 2 5.0 INDENTED LISTING OF SOURCE LINES ................... 5 6.0 CONTROL STRUCTURES ................................. 6 6.1 Decision Structures .................... 7 6.1.1 IF ...................... 7 6.1.2 UNLESS .................. 8 6.1.3 WHEN...ELSE ............. 9 6.1.4 CONDITIONAL .............10 6.1.5 SELECT ..................11 6.2 Loop Structures ........................12 6.2.1 DO ......................12 6.2.2 WHILE ...................13 6.2.3 REPEAT WHILE ............13 6.2.4 UNTIL ...................14 6.2.5 REPEAT UNTIL ............14 7.0 INTERNAL PROCEDURES ................................15 8.0 RESTRICTIONS .......................................18 9.0 ERROR HANDLING .....................................20 10.0 PROCEDURE FOR USE ..................................23 Appendices: A. FLECS Summary Sheet B. Available Documentation Concerning FLECS 1 FLECS USER'S MANUAL 1.0 INTRODUCTION ___ ____________ FORTRAN contains four basic mechanisms for controlling program flow: CALL/RETURN, IF, DO, and various forms of the GO TO. FLECS is a language extension of FORTRAN which has additional control mechanisms. These mechanisms make it easier to write FORTRAN by eliminating much of the clerical detail associated with constructing FORTRAN programs. FLECS is also easier to read and comprehend than FORTRAN. This manual is intended to be a brief but complete introduction to FLECS. It is not intended to be a primer on FLECS or structured programming. The reader is assumed to be a knowledgeable FORTRAN programmer. For programmers to whom transportability of their programs is a concern, it should be noted that the FLECS translator source code is in the public domain and is made freely available. The translator was written with transportability in mind and requires little effort to move from one machine to another. Those interested in moving FLECS to another machine or in having their own copy of FLECS should contact the author. FLECS is currently implemented on the PDP-10, the PDP- 11, the PDP-8, the CDC 6000 series, the UNIVAC 1100 series, the Honeywell 6000 series, and the IBM 360-370 series machines. The manner of implementation is that of a preprocessor which translates FLECS programs into FORTRAN programs. The resulting FORTRAN program is then processed in the usual way. The translator also produces a nicely formatted listing of the FLECS program which graphically presents the control structures used. Figure 1 illustrates the translating process. 2.0 RETENTION OF FORTRAN FEATURES ___ _________ __ _______ ________ The FLECS translator examines each statement in the FLECS program to see if it is an extended statement (a ________ _________ statement valid in FLECS but not in FORTRAN). If it is recognized as an extended statement, the translator generates the corresponding FORTRAN statements. If, however, the statement is not recognized as an extended statement, the translator assumes it must be a FORTRAN statement and passes it through unaltered. Thus the FLECS ___ _____ system does not restrict the use of FORTRAN statements; it ______ ____ ___ ________ ___ ___ __ _______ __________ simply provides a set of additional statements which may be Retention of FORTRAN Features 2 FLECS USER'S MANUAL Fig. 1 The translating process. used. In particular, GO TOs, arithmetic IFs, CALLs, arithmetic statement functions, and any other FORTRAN statements, compiler dependent or otherwise, may be used in a FLECS program. 3.0 CORRELATION OF FLECS AND FORTRAN SOURCES ___ ___________ __ _____ ___ _______ _______ One difficulty of preprocessor systems like FLECS is that error messages which come from the FORTRAN compiler must be related back to the original FLECS source program. This difficulty is overcome in the most recent MTS implementation by using the MTS line numbers (not to be ___ ____ _______ confused with FORTRAN internal statement numbers) associated with FLECS source statements. These line numbers appear on the FLECS listing and in the FORTRAN source listing. When an error message is produced by either the FLECS translator or the FORTRAN compiler, it will include the line number of the offending FLECS source statement, making it easy to locate on the listing. 4.0 STRUCTURED STATEMENTS ___ __________ __________ A basic notion of FLECS is that of the structured __________ statement which consists of a control phrase and its scope. _________ _______ ______ _____ FORTRAN has two structured statements, the logical IF and the DO. The examples in Figure 2 illustrate this terminology. Note that each structured statement consists of a control phrase which controls the execution of a set of one or more statements called its scope. Also note that each Structured Statements 3 FLECS USER'S MANUAL Fig. 2 Examples of structured statements. control phrase consists of a keyword plus some additional _______ information called the specification. A statement which _____________ does not consist of a control phrase and a scope is said to be a simple statement. Examples of simple statements are ______ _________ assignment statements, subroutine CALLs, arithmetic IFs, and GO TOs. The problem with the FORTRAN logical IF statement is that its scope may contain only a single simple statement. This restriction is eliminated in the case of the DO, but at the cost of clerical detail (having to stop thinking while a statement number is invented). Note also that the IF specification is enclosed in parentheses while the DO specification is not. In FLECS there is a uniform convention for writing control phrases and indicating their scopes. To write a structured statement, the keyword is placed on a line beginning in column 7 followed by its specification enclosed in parentheses. The remainder of the line is left blank. The statements comprising the scope are placed on successive lines. The end of the scope is indicated by a FIN statement. This creates a multi-line structured statement. __________ __________ _________ Structured Statements 4 FLECS USER'S MANUAL Examples of multi-line structured statements: IF (X.EQ.Y) U = V+W R = S+T --FIN DO (I = 1,N) A(I) = B(I)+C C = C*2.14-3.14 --FIN Note that the statement number has been eliminated from the DO specification since it is no longer necessary, the end of the loop being specified by the FIN. Nesting of structured statements is permitted to any depth. Here is an example of nested structured statements: IF (X.EQ.Y) U = V+W DO (I = 1,N) A(I) = B(I)+C C = C*2.14-3.14 --FIN R = S+T --FIN When the scope of a control phrase consists of a single simple statement, it may be placed on the same line as the ______ control phrase and the FIN may be dispensed with. This creates a one-line structured statement. ________ __________ _________ Examples of one-line structured statements: IF (X.EQ.Y) U = V+W DO (I = 1,N) A(I) = B(I)+C Since each control phrase must begin on a new line, it is not possible to have a one-line structured statement whose scope consists of a structured statement. Example of invalid construction: IF (X.EQ.Y) DO (I = 1,N) A(I) - B(I)+C To achieve the effect desired above, the IF must be written in a multi-line form. Structured Statements 5 FLECS USER'S MANUAL Example of valid construction: IF (X.EQ.Y) DO (I = 1,N) A(I) = B(I)+C --FIN In addition to IF and DO, FLECS provides several useful structured statements not available in FORTRAN. After a brief excursion into the subject of indentation, we will present these additional structures. 5.0 INDENTED LISTING OF SOURCE LINES ___ ________ _______ __ ______ _____ In the examples of multi-line structured statements above, the statements in the scope were indented and an "L" shaped line was drawn connecting the keyword of the control phrase to the matching FIN. The resulting graphic effect helps to reveal the structure of the program. The rules for using indentation and FINs are quite simple and uniform. The control phrase of a multi-line structured statement always causes indentation of the statements that follow. Nothing else causes indentation. A level of indentation (i.e. a scope) is always terminated with a FIN. Nothing else terminates a level of indentation. When writing a FLECS program on paper the programmer should adopt the indentation and line drawing conventions shown below. When preparing a FLECS source program in machine readable form, however, each statement should begin in column 7. When the FLECS translator produces the listing, it will reintroduce the correct indentation and produce the corresponding lines. Figure 3 shows the way a programmer should write a program, the way it is entered into the computer, and the corresponding listing produced by the FLECS translator. The correctly indented listing is a tremendous aid in reading and working with programs. Except for the dots and spaces used for indentation, the lines are listed exactly as they appear in the source program. That is, the internal spacing of columns 7-72 is preserved. There is seldom any need to refer to a straight listing of the unindented source. Comment lines are treated in the following way on the listing. A comment line which contains one or more non- blank characters in columns 2-6 will be listed with no indentation. A comment line with blanks in 2-6 will be listed with columns 7-72 being indented as if they were an executable statement, thus preventing the comment from Indented Listing of Source Lines 6 FLECS USER'S MANUAL 1. Program as written on paper by programmer. IF (X.EQ.Y) U = V+W DO (I = 1,N) A(I) = B(I)+C C = C*2.14-3.14 --FIN R = S+T --FIN 2. Program as entered into computer. IF (X.EQ.Y) U = V+W DO (I = 1,N) A(I) = B(I)+C C = C*2.14-3.14 FIN R = S+T FIN 3. Program as listed by FLECS translator. IF (X.EQ.Y) . U = V+W . DO (I = 1,N) . . A(I) = B(I)+C . . C = C*2.14-3.14 . ...FIN . R = S+T ...FIN Fig. 3 Examples of FLECS indentation. interrupting the dotted lines. Blank lines may also be placed in the source and will be treated as empty comments. 6.0 CONTROL STRUCTURES ___ _______ __________ The complete set of control structures provided by FLECS is given below together with their corresponding flow charts. The trigraph is used to indicate a logical expression. The trigraph is used to indicate a scope of one or more statements. Where more than one scope or logical expression is under consideration, means the first scope, means the second logical expression, and so on. Some statements, as indicated below, do not have a Control Structures 7 FLECS USER'S MANUAL one-line construction. A convenient summary of the information in this section may be found in Appendix A. 6.1 Decision Structures ___ ________ __________ Decision structures are structured statements which control the execution of their scopes on the basis of a logical expression or test. 6.1.1 IF Description: The IF statement causes a logical expression to be evaluated. If the value is true, the scope is executed once and control passes to the next statement. If the value is false, control passes directly to the next statement without execution of the scope. General Form: Flow Chart: IF ( ) Examples: IF (X.EQ.Y) U = V+W IF (T.GT.0.AND.S.LT.R) . I = I+1 . Z = 0.1 ...FIN Control Structures 8 FLECS USER'S MANUAL 6.1.2 UNLESS Description: "UNLESS ( )" is functionally equivalent to "IF( .NOT.( ) )", but is more convenient in some contexts. General Form: Flow Chart: UNLESS ( ) Examples: UNLESS (X.NE.Y) U = V+W UNLESS (T.LE.0 .OR. S.GE.R) . I = I+1 . Z = 0.1 ...FIN Control Structures 9 FLECS USER'S MANUAL 6.1.3 WHEN...ELSE Description: The WHEN...ELSE statements correspond to the IF...THEN...ELSE statement of Algol, PL/1, Pascal, etc. In FLECS, both the WHEN and the ELSE act as structured statements although only the WHEN has a specification. The ELSE statement must immediately follow the scope of the WHEN. The specifier of the WHEN is evaluated and exactly one of the two scopes is executed. The scope of the WHEN statement is executed if the expression is true and the scope of the ELSE statement is executed if the expression is false. In either case, control then passes to the next statement following the ELSE statement. General Form: Flow Chart: WHEN ( ) ELSE Examples: WHEN (X.EQ.Y) U = V+W ELSE U = V-W WHEN (X.EQ.Y) . U = V+W . T = T+1.5 ...FIN ELSE U =V-W WHEN (X.EQ.Y) U = V+W ELSE . U = V-W . T = T+1.5 ...FIN WHEN (X.EQ.Y) . U = V+W . T = T-1.5 ...FIN ELSE . V = V-W . T = T+1.5 ...FIN WHEN and ELSE always come as a pair of statements, never separately. Either the WHEN or the ELSE or both may assume the multi-line form. ELSE is considered to be a control phrase, hence cannot be placed on the same line as the WHEN. Thus "WHEN ( ) ELSE " is not valid. ___ Control Structures 10 FLECS USER'S MANUAL 6.1.4 CONDITIONAL Description: The CONDITIONAL statement is based on the LISP conditional. A list of logical expressions is evaluated one by one until the first expression to be true is encountered. The scope corresponding to that expression is executed, and control then passes to the first statement following the CONDITIONAL. If all expressions are false, no scope is executed. (See, however, the note about OTHERWISE below.) General Form: Flow Chart: CONDITIONAL . ( ) . ( ) . . . . . . . . . . ( ) ...FIN Examples: CONDITIONAL . (X.LT.-5.0) U = U+W . (X.LE.1.0) U = U+W+Z . (X.LE.10.5) U = U-Z ...FIN CONDITIONAL . (A.EQ.B) Z = 1.0 . (A.LE.C) . . Y = 2.0 . . Z = 3.4 . ...FIN . (A.GT.C .AND. A.LT.B) Z = 6.2 . (OTHERWISE) Z = 0.0 ...FIN The CONDITIONAL itself does not possess a one-line form. However, each "(
  • ) " is treated as a structured statement and may be in one-line or multi-line form. The reserved word OTHERWISE represents a catchall condition. That is, "(OTHERWISE) " is equivalent to "(.TRUE.) " in a CONDITIONAL statement. Control Structures 11 FLECS USER'S MANUAL 6.1.5 SELECT Description: The SELECT statement is similar to the CONDITIONAL but is more specialized. It allows an expression to be tested for equality to each expression in a list of expressions. When the first matching expression is encountered, a corresponding scope is executed and the SELECT statement terminates. In the description below, , ,..., represent arbitrary but compatible expressions. Any type of expression (INTEGER, REAL, COMPLEX,...) is allowed as long as the underlying FORTRAN system allows such expressions to be compared with an .EQ. or .NE. operator. General Form: Flow Chart: SELECT ( ) . ( ) . ( ) . . . . . . . . . . ( ) ...FIN Example: SELECT (OPCODE(PC)) . (JUMP) PC = AD . (ADD) . . A = A+B . . PC = PC+1 . ...FIN . (SKIP) PC = PC+2 . (STOP) CALL STOPCD ...FIN As in the case of CONDITIONAL, at most one of the will be executed. The catchall OTHERWISE may also be used in a SELECT statement. Thus "(OTHERWISE) " is equivalent to " " within a "SELECT ( )" statement. The expression is reevaluated for each comparison in the list, thus lengthy, time consuming, or irreproducable expressions should be precomputed, assigned to a variable, and the variable used in the specification portion of the SELECT statement. Control Structures 12 FLECS USER'S MANUAL 6.2 Loop Structures ___ ____ __________ The structured statements described below all have a scope which is executed a variable number of times depending on specified conditions. Of the five loops presented, the most useful are the DO, WHILE, and REPEAT UNTIL loops. To avoid confusion, the REPEAT WHILE and UNTIL loops should be ignored initially. Except for the DO, the presence of the keyword REPEAT implies that testing is done at the end of the loop. If ___ REPEAT is not present then testing is done at the beginning of the loop. 6.2.1 DO Description: The FLECS DO loop is functionally identical to the FORTRAN DO loop. The only differences are syntactic. In the FLECS DO loop, the statement number is omitted from the DO statement, the loop control parameters are enclosed in parentheses, and the scope is indicated by either the one line or multi-line convention. Since the semantics of the FORTRAN DO statement vary from one FORTRAN compiler to another, a flowchart cannot be given. With the IBM compilers, testing is done at the end of the loop. Ed. The symbol represents any legal loop control specification. General Form: Equivalent FORTRAN: DO DO 30 30 CONTINUE Examples: DO (I = 1,N) A(I) = 0.0 DO (J = 3,K,3) . B(J) = B(J-1)*B(J-2) . C(J) = SIN(B(J)) ...FIN Control Structures 13 FLECS USER'S MANUAL 6.2.2 WHILE Description: The WHILE loop causes its scope to be repeatedly executed while a specified condition is true. The condition is checked prior to the first execution of the scope; thus if the condition is initially false the scope will not be executed at all. General Form: Flow Chart: WHILE Examples: WHILE (X.LT.A(I)) I = I+1 WHILE (P.NE.0) . VAL(P) = VAL(P)+1 . P = LINK(P) ...FIN 6.2.3 REPEAT WHILE Description: By using the REPEAT verb, the test can be logically moved to the end of the loop. The REPEAT WHILE loop causes its scope to be repeatedly executed while a specified condition remains true. The condition is not checked until after the first execution of the scope. Thus the scope will always be executed at least once and the condition indicates under what conditions the scope is to be repeated. Note: "REPEAT WHILE" is functionally equivalent ________ to "REPEAT UNTIL(.NOT.( ))". General Form: Flow Chart: REPEAT WHILE ( ) Examples: REPEAT WHILE(N.EQ.M(I)) I = I+1 REPEAT WHILE (LINK(Q).NE.0) . R = LINK(Q) . LINK(Q) = P . P = Q . Q = R ...FIN Control Structures 14 FLECS USER'S MANUAL 6.2.4 UNTIL Description: The UNTIL loop causes its scope to be repeatedly executed until a specified condition becomes true. The condition is checked prior to the first execution of the scope, thus if the condition is initially true, the scope will not be executed at all. Note that "UNTIL ( )" is functionally equivalent to "WHILE ( .NOT.( ) )". General Form: Flow Chart: UNTIL ( ) Examples: UNTIL (X.EQ.A(I)) I = I+1 UNTIL (P.EQ.0) . VAL(P) = VAL(P)+1 . P = LINK(P) ...FIN 6.2.5 REPEAT UNTIL Description: By using the REPEAT verb, the test can be logically moved to the end of the loop. The REPEAT UNTIL loop causes its scope to be repeatedly executed until a specified condition becomes true. The condition is not checked until after the first execution of the scope. Thus the scope will always be executed at least once and the condition indicates under what conditions the repetition of __________ the scope is to be terminated. General Form: Flow Chart: REPEAT UNTIL ( ) Examples: REPEAT UNTIL (N.EQ.M(I)) I = I+1 REPEAT UNTIL (LINK(Q).EQ.0) . R = LINK(Q) . LINK(Q) = P . P = Q . Q = R ...FIN Control Structures 15 FLECS USER'S MANUAL 7.0 INTERNAL PROCEDURES ___ ________ __________ In FLECS a sequence of statements may be declared an internal procedure and given a name. The procedure may then ________ _________ be invoked from any point in the program by simply giving its name. Procedure names may be any string of letters, digits, _________ _____ and hyphens (i.e. minus signs) beginning with a letter and containing at least one hyphen. Internal blanks are not allowed. The only restriction on the length of a name is that it may not be continued onto a second line. Examples of valid internal procedure names: INITIALIZE-ARRAYS GIVE-WARNING SORT-INTO-DESCENDING-ORDER INITIATE-PHASE-3 A procedure declaration consists of the keyword "TO" _________ ___________ followed by the procedure name and its scope. The set of statements comprising the procedure is called its scope. If the scope consists of a single simple statement it may be placed on the same line as the "TO" and procedure name, otherwise the statements of the scope are placed on the following lines and terminated with a FIN statement. These rules are analogous with the rules for forming the scope of a structured statement. General Form of procedure declaration: TO procedure-name Examples of procedure declarations: TO RESET-POINTER P = 0 TO DO-NOTHING CONTINUE Internal Procedures 16 FLECS USER'S MANUAL TO SUMMARIZE-FILE . INITIALIZE-SUMMARY . OPEN-FILE . REPEAT UNTIL (EOF) . . ATTEMPT-TO-READ-RECORD . . WHEN (EOF) CLOSE-FILE . . ELSE UPDATE-SUMMARY . ...FIN . OUTPUT-SUMMARY ...FIN An internal procedure reference is a procedure name ________ _________ _________ appearing where an executable statement would be expected. In fact an internal procedure reference is an executable __ simple statement and thus may be used as the scope of a structured statement as in the last example above. When control reaches a procedure reference during execution of a FLECS program, a return address is saved and control is transferred to the first statement in the scope of the procedure. When control reaches the end of the scope, control is transferred back to the statement logically following the procedure reference. A typical FLECS program or subprogram consists of a sequence of FORTRAN declarations: (e.g. SUBROUTINE, INTEGER, DIMENSION, COMMON, etc.) followed by a sequence of executable statements called the body of the program ____ followed by the FLECS internal procedure declarations, if any, and finally the END statement. Figure 4 shows a complete (but uninteresting) FLECS program which illustrates the placement of the procedure declarations. The program is shown as it would be listed by the translator available through the FLECS/FORTRAN Interface (see Section 10). Note the MTS line numbers on the left, the use of a blank line (line 3) by the programmer, and the dashed lines generated by the translator to separate procedure declarations. Notes concerning internal procedures: 1. All internal procedure declarations must be placed at the end of the program just prior to the END statement. The appearance of the first "TO" statement terminates the body of the program. The translator expects to see nothing but procedure declarations from that point on. In particular, the translator will reject FORMAT statements, and thus they cannot be placed just before the END statement for the program. Suggested places for FORMAT statements are either next to their associated Internal Procedures 17 FLECS USER'S MANUAL MTS Line# Indented Source Listing... 1 C Interactive Program to Compute X**2. 2 C A zero input terminates execution. 3 4 REAL X,XSQ 5 REPEAT UNTIL (X.EQ.0) 6 . GET-A-VALUE-OF-X 7 . IF (X.NE.0) 8 . . COMPUTE-RESULT 9 . . TYPE-RESULT 10 . ...FIN 11 ...FIN 12 STOP ---------------------------------------- 13 TO GET-A-VALUE-OF-X 14 . PRINT 10 15 10 . FORMAT (' X = ') 16 . READ 20,X 17 20 . FORMAT (F10.5) 18 ...FIN --------------------------------------- 19 TO COMPUTE-RESULT XSQ = X*X --------------------------------------- 20 TO TYPE RESULT 21 . PRINT 30, XSQ 22 30 . FORMAT(' X-SQUARED = ',F7.2) 23 ...FIN 24 END Fig. 3 A program showing the use of internal procedures. I/O statement or after all declarations but before any executable statement or immediately preceding the first procedure declaration. 2. The order of the declarations is not important. Alphabetical by name is an excellent order for programs with a large number of procedures. The translator prints a procedure cross reference table at the end of the source statement listing to assist in finding procedure references and declarations. Internal Procedures 18 FLECS USER'S MANUAL 3. Procedure declarations may not be nested. That is, the scope of a procedure may not contain a procedure declaration. It may, of course, contain executable procedure references. 4. Any procedure may contain references to any other procedures but not to itself. 5. Dynamic recursion of procedure referencing is not permitted. 6. All program variables are global and accessible to the statements in any procedure. 7. There is no formal mechanism for defining or passing parameters to an internal procedure. When parameter passing is needed, the FORTRAN function or subroutine subprogram mechanism may be used or the programmer may invent his own parameter passing methods using the global nature of variables over internal procedures. 8. The FLECS translator separates procedure declarations on the listing by dashed lines as shown in Fig. 4. 8.0 RESTRICTIONS ___ ____________ If FLECS were implemented by a nice intelligent compiler this section would be much shorter. Currently, however, FLECS is implemented by a sturdy but naive one-pass translator. Thus the FLECS programmer must observe the following restrictions. 1. FLECS must invent many statement numbers in creating the FORTRAN program. It does so by beginning with a large number, 99999, and generating successively smaller numbers as it needs them. Do not use a number which will be generated by the translator. A good rule of thumb is to avoid using 5-digit statement numbers. _____ _____ _______ _________ _______ 2. The FLECS translator must generate integer variable names. It does so by using names of the form "Innnnn" when nnnnn is a 5-digit number related to a generated statement number. Do not use variables of the form __ ___ ___ _________ __ ___ ____ Innnnn and avoid causing them to be declared other than ______ ___ _____ _______ ____ __ __ ________ _____ ____ INTEGER. For example, the declaration "IMPLICIT REAL _______ (A-Z)" leads to trouble. Try "IMPLICIT REAL (A-H, J-Z)" instead. 3. The translator does not handle FORTRAN statement continuation lines. Thus FORTRAN statements may be Restrictions 19 FLECS USER'S MANUAL continued since the statement and its continuations will be passed through the translator without alteration. (See Chapter 2.) However, an extended FLECS statement __ ________ _____ _________ (including IF) which requires translation may not be __________ ___ _____ ________ ___________ ___ ___ __ continued. The reasons one might wish to continue a _________ FLECS statement are 1) It is a structured statement or procedure declaration with a one-statement scope too long to fit on a line, or 2) it contains an excessively long specification portion or 3) both of the above. Problem 1) can be avoided by going to the multi-line form. Frequently problem 2) can be avoided in case the specification is an expression (logical or otherwise) by assigning the expression to a variable in a preceding statement and then using the variable as the specification. 4. Blanks are meaningful separators in FLECS. Don't put ______ ___ __________ __________ __ ______ _____ them in dumb places like the middle of identifiers or key words and do use them to separate different words __ like REPEAT and UNTIL. 5. Let FLECS indent the listing. Start all statements in _____ ___ __________ __ col. 7 and the listing will always reveal the true ____ _ structure of the program (as understood by the translator, of course). 6. As far as the translator is concerned, FORMAT statements are executable FORTRAN statements since it doesn't recognize them as extended FLECS statements. Thus, only ____ place FORMAT statements where an executable FORTRAN _____ ______ __________ _____ __ __________ _______ statement would be acceptable. Don't put them between _________ _____ __ __________ the end of a WHEN statement and the beginning of an ELSE statement. Don't put them between procedure declarations. Incorrect examples: Corrected Examples: WHEN (FLAG) WRITE(3,30) WHEN (FLAG) 30 FORMAT(7H TITLE:) . WRITE(3,30) ELSE LINE = LINE+1 30 . FORMAT(7H TITLE:) ...FIN ELSE LINE = LINE+1 TO WRITE-HEADER TO WRITE-HEADER . PAGE = PAGE+1 . PAGE = PAGE+1 . WRITE(3,40) H,PAGE . WRITE(3,40) H,PAGE ...FIN 40 . FORMAT(70A1,I3) 40 FORMAT (70A1,I3) ...FIN 7. The translator, being simple-minded, recognizes extended FLECS statements by the process of scanning the first identifier on the line. If the identifier is one of the Restrictions 20 FLECS USER'S MANUAL FLECS keywords IF, WHEN, UNLESS, FIN, etc., the line is assumed to be a FLECS statement and is treated as such. Thus, FLECS keywords are reserved and may not be used as _____ ________ ___ ________ ___ ___ ___ __ ____ __ variable names. In case of necessity, a variable name, ________ _____ say WHEN, may be slipped past the translator by embedding a blank within it. Thus "WH EN" will look like "WH" followed by "EN" to the translator which is blank sensitive, but like "WHEN" to the compiler which ignores blanks. 8. In scanning a parenthesized specification, the translator scans from left to right to find the parenthesis which matches the initial left parenthesis of the specification. The translator, however, is ignorant of FORTRAN syntax including the concept of Hollerith constants and will treat Hollerith parentheses as syntactic parentheses. Thus, avoid placing Hollerith _____ _______ _________ constants containing unbalanced parentheses within _________ __________ __________ ___________ ______ specifications. If necessary, assign such constants to ______________ a variable, using a DATA or assignment statement, and place the variable in the specification. Incorrect Example: Corrected Example: IF (S.EQ.'(') DATA LP/'('/ IF(S.EQ.LP) 9. The FLECS translator will not supply the statements necessary to cause appropriate termination of main and sub-programs. Thus it is necessary to include the __ __ _________ __ _______ ___ appropriate RETURN, STOP, or CALL SYSTEM statement prior ___________ _______ _____ __ ____ ______ _________ _____ to the first internal procedure declaration. Failure to __ ___ _____ ________ _________ ___________ do so will result in control entering the scope of the first procedure after leaving the body of the program. Do not place such statements between the procedure declarations and the END statement. 9.0 ERROR HANDLING ___ _____ ________ This section provides a framework for understanding the error handling mechanisms of version 22 of the FLECS Translator. The system described below is at an early point in evolution, but has proven to be quite workable. The FLECS translator examines a FLECS program on a line by line basis. As each line is encountered it is first subjected to a limited syntax analysis followed by a context ______ _______ analysis. Errors may be detected during either of these analyses. It is also possible for errors to go undetected __________ by the translator. Error Handling 21 FLECS USER'S MANUAL 9.1 Syntax Errors ___ ______ ______ When a syntax error is detected by the translator, it ignores the statement. On the FLECS listing the line number _______ ___ _________ of the statement is overprinted with hyphens to indicate that the statement has been ignored. The nature of the syntax error is given in a message on the following line. The fact that a statement has been ignored may, of course, cause some context errors in later statements. For example, the control phrase "WHEN (X(I).LT.(3+4)" has a missing right parenthesis. This statement will be ignored, causing as a minimum the following ELSE to be out of context. The programmer should be, of course, be aware of such effects. More is said about them in the next section. 9.2 Context Errors ___ _______ ______ If a statement successfully passes the syntax analysis, it is checked to see if it is in the appropriate context within the program. For example, an ELSE must appear following a WHEN and nowhere else. If an ELSE does not appear at the appropriate point or if it appears at some other point, then a context error has occurred. A frequent source of context errors in the initial stages of development of a program comes from miscounting the number of FIN's needed at some point in the program. With the exception of excess FIN's which do not match any preceding control phrase and are ignored (as indicated by overprinting with hyphens), all context errors are treated with a uniform strategy. When an out-of-context source statement is encountered, the translator generates a "STATEMENT(S) NEEDED" message. It then invents and processes a sequence of statements which, if they had been included at that point in the program, would have placed the original source statement in a correct context. A message is given for each such statement invented. The original source statement is then processed in the newly created context. By inventing statements the translator is not trying to patch up the program so that it will run correctly; it is simply trying to adjust the local context so that the original source statement and the statements which follow will be acceptable on a context basis. As in the case of context errors generated by ignoring a syntactically incorrect statement, such an adjustment of context frequently causes further context errors later on. This is called propagation of context errors. ___________ __ _______ ______ Error Handling 22 FLECS USER'S MANUAL One useful feature of the context adjustment strategy is that context errors cannot propagate past a recognizable procedure declaration. This is because the "TO" declaration is in context only at indentation level 0. Thus to place it in context, the translator must invent enough statements to terminate all open control structures which precede the "TO". The programmer who modularizes his program into a collection of relatively short internal procedures limits the potential for propagation of context errors. 9.3 Undetected Errors ___ __________ ______ The FLECS translator is ignorant of most details of FORTRAN syntax. Thus most FORTRAN syntax errors will be detected by the FORTRAN compiler, not the FLECS translator. In addition, there are two major classes of FLECS errors which will be caught by the compiler and not by the translator. The first class of undetected errors involve misspelled FLECS keywords. A misspelled keyword will not be recognized by the translator. The line on which it occurs will be assumed to be a FORTRAN statement and will be passed unaltered to the compiler which will no doubt object to it. For example, a common error is to spell UNTIL with two L's. Such statements are passed to the compiler, which then produces an error message. The fact that an intended control phrase was not recognized frequently causes a later context error since a level of indentation is not triggered. The second class of undetected errors involves unbalanced parentheses. (See also note 8 in Section 8.0.) When scanning a parenthesized specification, the translator is looking for a matching right parenthesis. If the matching parenthesis is encountered before the end of the line, the remainder of the line is scanned. If the remainder is blank or consists of a recognizable internal procedure reference, all is well. If neither of the above two cases hold, the remainder of the line is assumed _______ (without checking) to be a simple FORTRAN statement which is passed to the Compiler. Of course, this assumption may be wrong. Thus the statement "WHEN (X.LT.A(I)+Z)) X = 0" is broken into keyword "WHEN" specification "(X.LT.A(I)+Z)" FORTRAN statement ") X = 0" Error Handling 23 FLECS USER'S MANUAL Needless to say the compiler will object to ") X = 0" as a statement. Programmers may run into difficulty due to the propagation of context errors. Due to the context error, the FLECS system may not proceed with compilation, and hence the programmer is sometimes not warned of the genuine cause of the error by the compiler. One indication of the true source of the error may be an indentation failure at the corresponding point in the listing of the FLECS source statements. The programmer using FLECS should always subject his FLECS listing to a careful reading before directing the system to compile the preprocessor output. 9.4 Other Errors ___ _____ ______ The translator detects a variety of other errors such as multiply defined, or undefined procedure references. The error messages are self-explanatory. (Really and truly!) 10.0 PROCEDURE FOR USE ____ _________ ___ ___ The FLECS/FORTRAN Interface supersedes the standalone _____________ _________ processor for most MTS use. The Interface sequences the operation of the preprocessor and the compiler so that a set of FLECS source modules may be processed directly through to object module form using a single MTS command. Management of the target modules is performed entirely by the Interface, and the target modules are never written into an MTS file unless explicitly requested by the user. In addition, all error diagnostics from both the preprocessor ____ and the FORTRAN compiler are given in terms of MTS line numbers. The Interface is documented in the memo "The FLECS/FORTRAN Interface", in the file UNSP:FLX.W. Please communicate questions and problems with the use of FLECS in MTS to the editor. Procedure for Use APPENDIX B Available Documentation Concerning FLECS University of Oregon Documents Available from the Author (as of August, 1974): Beyer, T., Flecs User's Manual (University of Oregon _____ ______ ______ Edition) A concise description of the FLECS extension of FORTRAN and of the details necessary to run a FLECS program on the PDP-10 or on the IBM System/360 at the University of Oregon. Beyer, T., FLECS: System Modification Guide ______ ______ ____________ _____ Information of interest to anyone who wishes to install or adapt the FLECS system to a new machine or operating system. Also of interest to those who wish to reduce the execution time of the system by rewriting some system subroutines in assembly language. Beyer, T., FLECS Installation Guide _____ ____________ _____ A concise guide to installing the FLECS processor on a new computing system. Beyer, T., FLECS: General Information Letter ______ _______ ___________ ______ Background information on the FLECS system and details on ordering the preprocessor and documentation from the University of Oregon. University of Michigan Documents Available from the Editor: Cederquist, G. N. (ed.), FLECS User's Manual (University of _____ ______ ______ Michigan Edition) A concise description of the FLECS extension of FORTRAN and its behavior in the MTS environment at the University of Michigan. Also contains procedures for use of the standalone preprocessor as received from the University of Oregon. Cederquist, G. N. The FLECS/FORTRAN Interface ___ _____________ _________ Instructions on how to use the FLECS/FORTRAN Interface program to preprocess and compile FLECS programs with only a single MTS command. The Interface is the preferred way of using FLECS under MTS at the University of Michigan. Appendix B