DOCUMENT MP-1-3415 | File: CLUSTER::[MP1Q.MANUALS]FLECSUIM.RNO | | Under RSX-11M and VMS FLECS and ALECS User's Manual This manual corresponds to version 22 of FLECS As Modified at LAMPF | August 27, 1984 GROUP MP-1 Clinton P. Anderson Meson Physics Facility (LAMPF) Los Alamos National Laboratory Los Alamos, New Mexico 87545 Page 2 TABLE OF CONTENTS CONTENTS 1 INTRODUCTION . . . . . . . . . . . . . . . . . . . . 5 1.1 Retention Of FORTRAN Features . . . . . . . . . . 5 1.2 Correlation of FLECS and FORTRAN Sources . . . . . 6 2 STRUCTURED STATEMENTS . . . . . . . . . . . . . . . 8 3 INDENTATION, LINES, AND THE LISTING . . . . . . . 11 4 CONTROL STRUCTURES . . . . . . . . . . . . . . . . 13 4.1 Decision Structures . . . . . . . . . . . . . . 13 4.1.1 IF . . . . . . . . . . . . . . . . . . . . . . . 13 4.1.2 UNLESS . . . . . . . . . . . . . . . . . . . . . 13 4.1.3 WHEN...ELSE . . . . . . . . . . . . . . . . . . 14 4.1.4 CONDITIONAL . . . . . . . . . . . . . . . . . . 15 4.1.5 SELECT . . . . . . . . . . . . . . . . . . . . . 16 4.2 Loop Structures . . . . . . . . . . . . . . . . 16 4.2.1 DO . . . . . . . . . . . . . . . . . . . . . . . 17 4.2.2 WHILE . . . . . . . . . . . . . . . . . . . . . 17 4.2.3 REPEAT WHILE . . . . . . . . . . . . . . . . . . 18 4.2.4 UNTIL . . . . . . . . . . . . . . . . . . . . . 18 4.2.5 REPEAT UNTIL . . . . . . . . . . . . . . . . . . 19 5 INTERNAL PROCEDURES . . . . . . . . . . . . . . . 20 6 RESTRICTIONS AND NOTES . . . . . . . . . . . . . . 23 7 ERRORS . . . . . . . . . . . . . . . . . . . . . . 26 7.1 Syntax Errors . . . . . . . . . . . . . . . . . 26 7.2 Context Errors . . . . . . . . . . . . . . . . . 26 7.3 Undetected Errors . . . . . . . . . . . . . . . 27 7.4 Other Errors . . . . . . . . . . . . . . . . . . 28 8 ALECS - FLECS FOR ASSEMBLY LANGUAGE ROUTINES . . . 29 8.1 ALECS Operators . . . . . . . . . . . . . . . . 29 8.2 ALECS Control Structures . . . . . . . . . . . . 31 8.3 ALECS Restrictions and Notes . . . . . . . . . . 33 9 FLECS DIRECTIVES . . . . . . . . . . . . . . . . . 36 9.1 No Translation Flag . . . . . . . . . . . . . . 36 9.2 .PAGE Directive . . . . . . . . . . . . . . . . 36 9.3 .NAME Directive . . . . . . . . . . . . . . . . 36 9.4 .INCLUDE Directive . . . . . . . . . . . . . . . 37 Page 3 9.5 Conditional Translation Directives . . . . . . . 38 9.6 .IMPLICIT NONE Directive . . . . . . . . . . . . 39 10 PROCEDURE FOR USE . . . . . . . . . . . . . . . . 41 APPENDIX A FLOW CHARTS FOR FLECS STATEMENTS APPENDIX B AVAILABLE DOCUMENTATION CONCERNING FLECS (December, 1974) INDEX Page 4 ABSTRACT This document describes the FLECS and ALECS programming languages which allow use of standard structured programming techniques in FORTRAN and MACRO-11 programs, respectively. REVISION LIST 05-Jan-75 (Terry Beyer) written. 17-Jan-79 (Civil Aeromedical Institute) put into RUNOFF format. 01-Oct-82 (MAO) revised to currently used FLECS/ALECS at LAMPF; DSR format. 19-Sep-83 (MAO) Document new listing format, new command files, response to long lines, and generation of either PDP or VAX MACRO. 27-Aug-84 (MAO) Document ".IMPLICIT NONE"; revise Sec. 10. Page 5 1 INTRODUCTION FORTRAN contains four basic mechanisms for controlling program flow: CALL/RETURN, IF, DO, and various forms of the GO TO. _ _ _ _ _ FLECS (FORTRAN Language Extensions and Control Structures) has additional control mechanisms that 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. This manual is a brief, but complete, introduction to FLECS. It is not a primer on FLECS or structured programming. The reader is assumed to be a knowledgeable FORTRAN programmer. Programmers to whom transportability of their programs is a concern should note 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. FLECS is implemented on both the PDP-11 and the VAX-11/780. The manner of implementation is that of a preprocessor that 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 that graphically presents the control structures used. The following diagram illustrates the translating process: FLECS FLECS Translated Source----------->Translator--------->FORTRAN Program ! source ! ! ! ! Indented To Listing FORTRAN Compiler The usefulness of FLECS for FORTRAN programs makes it clear that a structured preprocessor is desirable for any language lacking the appropriate constructs. At LAMPF, we have therefore implemented an "ALECS" preprocessor for PDP MACRO-11 or VAX-11 MACRO assembly language routines. ALECS implements all of the structured constructs used in FLECS (except DO). Except as noted, the material in this manual applies to both ALECS and FLECS. However, in Sec. 8, some special restrictions and features of ALECS are given. _________ __ _______ ________ 1.1 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 Page 6 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 additional statements which may be 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. Similarly, ALECS allows full use of MACRO-11 or VAX-11 MACRO features. FORTRAN has a number of special conventions for dealing with tabs, and FLECS/ALECS use the same conventions (see the FORTRAN language manual). Throughout this manual, we will describe statements as starting in column 7, etc., but, in fact, the FORTRAN tab conventions are also allowed. ___________ __ _____ ___ _______ _______ 1.2 Correlation of FLECS and FORTRAN Sources One difficulty of preprocessor systems like FLECS is that error messages that come from the FORTRAN compiler must be related back to the original FLECS source program. This difficulty is reduced by the translator by putting the FLECS line number in columns 73-80 of the FORTRAN code. Thus, if the compiler flags a line of input as being in error, check that line in the FORTRAN input file and at its end will be the number of the source line in the FLECS input file. Note that a FLECS line may produce more than one line of FORTRAN code, so several lines of FORTRAN code may point to the same location in the FLECS input. On the FLECS listing file the FLECS line number is given in the leftmost column. To the right of these numbers is given the line number of the FORTRAN code generated by that FLECS line. The FORTRAN line number is useful if you get a FORTRAN execution-time error with a FORTRAN line number and you only have the FLECS listing file. The FORTRAN line numbers given in the FLECS file disagree with the true FORTRAN line numbers in the following cases: 1. D-lines are always counted by FLECS. Thus the line numbers are correct only if FORTRAN compiles D-lines. 2. Lines from FORTRAN INCLUDE files are not counted by FLECS. To get such lines counted, use a FLECS .INCLUDE file (see Sec. 9.4). 3. Lines with FLECS keywords may generate from zero to many lines of FORTRAN code. For such keyword lines, the FORTRAN line number will be either the last or next to last FORTRAN line actually generated. Page 7 Note PDP and VAX FORTRAN compilers number lines differently, so do not be surprised if FLECS listings are different for the two systems. Also note the FLECS /FU switch may change the line numbering. Page 8 2 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 following example illustrates this terminology: structured statement :----------------------------------: control phrase scope :-----------------------: :--------: keyword specification :--------: :------------: IF (X.EQ.Y) U=V+W keyword specification :--------: :------------: DO 30 I = 1,N control phrase ) A(I) = B(I)+C ) ( structured L(I) = I-K(I) ( scope ( statement 30 CONTINUE ) ) Note that each structured statement consists of a control phrase that controls the execution of a set of one or more statements called its scope. Also note that each control phrase consists of a _______ _____________ keyword plus some additional information called the specification. A statement that 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 about the problem 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. In writing 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 except for comments (see Sec. 10). The statements composing the scope are placed on successive lines. The end of the scope is indicated by a FIN _________ __________ statement. This creates a multiline structured statement. Page 9 Examples of multiline 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: 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. 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 multiline form. Page 10 Example of valid construction: IF (X.EQ.Y) | DO (I=1,N) A(I) = B(I)+C |__FIN FLECS provides, in addition to IF and DO, several useful structured statements not available in FORTRAN. After a brief excursion into the subject of indentation, we will present these additional structures. Page 11 3 INDENTATION, LINES, AND THE LISTING In the examples of multiline 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 multiline 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 by 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 in FLECS listings. 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 corresponding lines. If the programmer attempts to introduce his own indentation with the use of leading blanks, the program will be translated correctly, but the resulting listing will be improperly indented. Example of indentation: 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 Page 12 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 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 the straight listing of the source that is not indented. Comment lines are treated in the following way on the listing to prevent interruption of the dotted lines indicating scope. A comment line that contains only blanks in columns 2-6 will be listed with columns 7-72 indented at the then-current level of indentation as if the line were an executable statement. If, however, one or more nonblank characters appear in columns 2-6 of a comment line, the line will be listed without indentation. Blank lines may be inserted in the source and will be treated as empty comments. Page 13 4 CONTROL STRUCTURES The complete set of control structures provided by FLECS is given below. The symbol [L] is used to indicate a logical expression. The symbol $ is used to indicate a scope of one or more statements. Some statements, as indicated below, do not have a one-line construction. A convenient summary of the information in this section may be found in Appendix A along with flow charts for the structures. ________ __________ 4.1 Decision Structures Decision structures are structured statements that control the execution of their scopes on the basis of a logical expression or test. Flow charts for the structures are given in Appendix A. __ 4.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 following the scope without execution of the scope. General form: IF ( [L] ) $ Examples: IF (X.EQ.Y) U = V+W IF (T.GT.0.AND.S.LT.R) . I = I+1 . Z = 0.1 ...FIN ______ 4.1.2 UNLESS - Description: "UNLESS ( [L] )" is functionally equivalent to "IF (.NOT.( [L] ))" but is more convenient in some contexts. General Form: UNLESS ( [L] ) $ Page 14 Examples: UNLESS (X.NE.Y) U = V+W UNLESS (T.LE.0.OR.S.GE.R) . I = I+1 . Z = 0.1 ...FIN ___________ 4.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 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 passes to the next statement following the scope of the ELSE statement. General form: WHEN ( [L] ) $1 ELSE $2 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 . U = V-W . T = T+1.5 ...FIN Page 15 Note: WHEN and ELSE always come as a pair of statements, never separately. Either the WHEN or the ELSE or both may assume the multiline form. ELSE is considered to be a control phrase, hence it cannot be placed on the same line as WHEN. Thus, ___ "WHEN ( [L] ) $1 ELSE $2" is not valid. ___________ 4.1.4 CONDITIONAL - Description: The CONDITIONAL statement is based on the LISP conditional. Logical expressions are evaluated one by one until the first true expression is encountered. The scope corresponding to that expression is executed, and control then passes to the first statement following the scope of the CONDITIONAL. If all expressions are false, no scope is executed. (See, however, the note about OTHERWISE below.) General Form: CONDITIONAL . ( [L1] ) $1 . ( [L2] ) $2 . . . . . . . . . . ( [Ln] ) $n ...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 Note that the CONDITIONAL itself does not possess a one-line form. However, each "( [Li] ) $i" is treated as a structured statement and may be in one-line or multiline form. Note also that the reserved word OTHERWISE represents a catchall condition. That is, "(OTHERWISE) $i" is equivalent to "(.TRUE.) $i" in a CONDITIONAL statement. Page 16 ______ 4.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, [EL1], [EL2],..., [EL3] 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. For ALECS, only word (16-bit) expressions are allowed. General Form: SELECT ( [EL] ) . ( [EL1] ) $1 . ( [EL2] ) $2 . . . . . . . . . . ( [ELn] ) $n ...FIN Example: SELECT (OPCODE(PC)) . (JUMP) PC = AD . (ADD) . . A = A+B . . PC = PC+1 . ...FIN . (SKIP) PC = PC+2 . (STOP) CALL STOPCD ...FIN Note that, as in the case of CONDITIONAL, at most one of the $i will be executed. Note too that the catchall OTHERWISE may also be used in a SELECT statement. Thus, "(OTHERWISE) $n" is equivalent to "([EL]) $n" within a "SELECT ([EL])" statement. Also note that the expression [EL] 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. ____ __________ 4.2 Loop Structures The structured statements described below all have a scope that 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. Page 17 __ 4.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 incrementation parameters are enclosed in parentheses, and the scope is indicated by either the one-line or multiline convention. Since the semantics of the FORTRAN DO statement vary from one FORTRAN compiler to another, a flowchart cannot be given. The symbol I@ represents any legal incrementation specification. General Form: Equivalent FORTRAN: DO (I@) $ DO 30 I@ $ 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 Note: DO is not supported by ALECS. _____ 4.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 loop. Thus, if the condition is initially false, the scope will not be executed at all. General Form: WHILE ( [L] ) $ Examples: WHILE (X.LT.A(I)) I=I+1 WHILE (P.NE.0) . VAL(P) = VAL(P)+1 . P = LINK(P) ...FIN Page 18 ______ _____ 4.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 loop. Thus, the scope will always be executed at least once, and the condition indicates under what conditions the scope is to be repeated. Note that "REPEAT WHILE([L])" is functionally equivalent to "REPEAT UNTIL(.NOT.([L]))." General Form: REPEAT WHILE ([L]) $ 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 _____ 4.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 ([L])" is functionally equivalent to "WHILE (.NOT.([L]))." General Form: UNTIL ( [L] ) $ Examples: UNTIL (X.EQ.A(I)) I = I+1 UNTIL (P.EQ.0) . VAL(P) = VAL(P)+1 . P = LINK(P) ...FIN Page 19 ______ _____ 4.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: REPEAT UNTIL ( [L] ) $ 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 Page 20 5 INTERNAL PROCEDURES In FLECS, a sequence of statements may be declared to be 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 INITITATE-PHASE-3 _________ ___________ A procedure declaration consists of the keyword "TO" followed by the procedure name and its scope. The set of statements composing 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 to the rules for forming the scope of a stuctured statement. General form of procedure declarations: TO procedure-name Examples of procedure declarations: TO RESET-POINTER P = 0 TO DO-NOTHING CONTINUE 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 in 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. Page 21 A typical FLECS program or subprogram consists of a sequence of FORTRAN declarations (e.g., 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. Here is a complete (but uninteresting) FLECS program that illustrates the placement of the procedure declarations. 00010 C INTERACTIVE PROGRAM FOR PDP-10 TO COMPUTE X**2. 00020 C ZERO IS USED TO TERMINATE EXECUTION. 00030 00040 REAL X,XSQ 00050 REPEAT UNTIL (X.EQ.0) 00060 . GET-A-VALUE-OF-X 00070 . IF (X.NE.0) 00080 . . COMPUTE-RESULT 00090 . . TYPE-RESULT 00100 . ...FIN 00110 ...FIN 00120 CALL EXIT ---------------------------------------- 00130 TO GET-A-VALUE-OF-X 00140 . TYPE 10 00150 10 . FORMAT (' X = ',$) 00160 . ACCEPT 20,X 00170 20 . FORMAT(F) 00180 ...FIN ---------------------------------------- 00190 TO COMPUTE-RESULT XSQ = X*X ---------------------------------------- 00200 TO TYPE-RESULT 00210 . TYPE 30, XSQ 00220 30 . FORMAT(' X-SQUARED = ',F7.2) 00230 ...FIN 00240 END Page 22 Notes concerning internal procedures: 1. All internal procedure declarations must be placed at the end of the program just prior to the END statement (.END in ALECS). 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. 2. The order of the declarations is not important. Alphabetical by name is an excellent order for programs with a large number of procedures. 3. Procedure declarations may not be nested. In other words, 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 excluding itself. 5. Dynamic recursion of procedure referencing is not permitted. 6. All program variables within a main or subprogram are global and are accessible to the statements in all procedures declared within that same main program or subprogram. 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 the preceding example. Page 23 6 RESTRICTIONS AND NOTES 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 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 (32760 at LAMPF) and generating successively smaller numbers as it needs them. Do not use a number that 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" where 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 "IMPLICT REAL (A-H,J-Z)" instead. (Note | that the ".IMPLICIT NONE" statement described in Sec. 9.6 | is compatible with this restriction.) 3. The translator does not recognize continuation lines in the source file. Thus, FORTRAN statements may be continued, since the statement and its continuations will be passed through the translator without alteration (see __ ___ ________ __ ________ _____ Sec. 1.1). However, do not continue an extended FLECS _________ _____ ________ ___________ statement which requires translation. 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 the above. Problem (1) can be avoided by going to the multiline form. Frequently, problem (2) can be avoided when 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 statements; _____ ___ ____ __ ____ ______ don't put then in dumb places like the middle of __ identifiers or key words, and do use them to separate distinct words like REPEAT and UNTIL. 5. Let FLECS indent the listing. If you start all statements in column 7, 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, place ______ __________ ____ _____ __ __________ _______ format statements only where an executable FORTRAN Page 24 _________ _____ __ __________ 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 Usage: Corrected Usage: 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 FLECS keywords IF, WHEN, UNLESS, FIN, etc., the line is assumed to be a FLECS statement and is treated as such. ___ _____ ________ ___ _________ __ ___ ___ ____ __ Thus, the FLECS keywords are reserved; do not use them 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 that 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 Hollerith constants containing unbalanced ___________ ______ ______________ parentheses within specifications. If necessary, assign such constants to a variable by using DATA or assignment statements, and place the variable in the specification. Incorrect Usage: Corrected Usage: IF (J.EQ.'(') LP = '(' IF (J.EQ.LP) 9. The FLECS translator will not supply the statements necessary to cause appropriate termination of main ______ _______ ___ programs and subprograms. Thus, always include the ___________ _______ _____ __ ____ ____ _________ _____ __ appropriate RETURN, STOP, or CALL EXIT 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 Page 25 and the END statement. Page 26 7 ERRORS 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 it has proved to be quite workable. The FLECS translator examines a FLECS program line by line. As each line is encountered, the translator first subjects it to a ______ _______ limited syntax analysis and then a context analysis. Errors may be detected during either of these analyses. It is also possible for __________ errors to go undetected by the translator. ______ ______ 7.1 Syntax Errors _______ When the translator detects a syntax error, it ignores the _________ statement. On the FLECS listing, the line number of the statement is preceded by an "E" 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, of course, be aware of such effects. More will be said about these effects below. _______ ______ 7.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 after 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 FINs needed at some point in the program. With the exception of excess FINs that do not match any preceding control phrase and are ignored, 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 that, had it 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. Page 27 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 that 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. One nice 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 the "TO" in context, the translator must invent enough statements to teminate 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. __________ ______ 7.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 rather than by the FLECS translator. For ALECS, MACRO syntax errors will be detected by the assembler. In addition, there are two major classes of FLECS errors that will be caught by the compiler and not by the translator. The first class of undetected errors involves misspelled FLECS keywords. A misspelled keyword will not be recognized by the translator. It will assume the line on which the word occurs to be a FORTRAN statement and will pass the line unaltered to the compiler, which will no doubt object to it. For example, a common error is spelling UNTIL with two Ls. 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 will not be triggered. The second class of undetected errors involves unbalanced parentheses (see also Note 8 in Sec. 6). When scanning a parenthesized specification, the translator looks for a close parenthesis to match the initial open parenthesis that begins the specification. As soon as it finds one, it assumes that the remainder of the line is a simple FORTRAN statement, which it passes to the compiler. Of course, this assumption may be wrong. Thus, the statement Page 28 WHEN (X.LT.A(I)+Z)) X = 0 is broken into keyword "WHEN" specification "(X.LT.A(I)+Z)" FORTRAN statement ") X = 0" Needless to say, the compiler will object to ") X = 0" as a statement. Programmers on batch-oriented systems have less difficulty with undetected errors due to the practice of running the program through both the translator and the compiler each time a run is submitted. The compiler errors usually point out any errors undetected by the translator. Programmers on interactive systems tend to have a bit more difficulty, since an undetected error in one line may trigger a context error in a much later line. Noticing the context error, the programmer does not proceed with compilation and hence is not warned by the compiler of the genuine cause of the error. One indication of the true source of the error may be an indentation failure at the corresponding point in the listing. _____ ______ 7.4 Other Errors If FLECS or ALECS reads an input line longer than 80 characters, the warning mesage (READ ERROR ON INPUT LINE) is produced and the input is truncated to 80 characters. If the FLECS translation produces a FORTRAN output line containing more than 72 characters, the warning message *****WARN-INPUT FORCED OUTPUT CONTINUATION LINE is produced. In the former case input information is lost and in the latter case FLECS occasionally produces an incorrect FORTRAN continuation line. Thus if you get one of these messages, it is best to shorten the input line. The translator detects a variety of other errors, such as multiple defined or undefined procedure references. The error messages are self-explanatory. (Really and truly!) Page 29 8 ALECS - FLECS FOR ASSEMBLY LANGUAGE ROUTINES If you do not wish to use the FLECS structured statements in assembly language programs, you may skip this section. ALECS has no effect on the use of FLECS for FORTRAN routines. The FLECS structured statements and listing files are sufficiently useful that they have been implemented for PDP MACRO-11 and VAX-11 MACRO assembly language. The preprocessor is _ _ _ _ _ named ALECS (Assembly Language Extensions and Control Structures). ALECS provides the FLECS control structures for use in assembly language along with a number of special operators to make them easy to use. _____ _________ 8.1 ALECS Operators The control structures require a specification (see Sec. 2.0) with a logical value of true or false. FORTRAN (and thus FLECS) provides a number of operators to make production of a logical value simple when given nonlogical variables to be compared. For example, in IF(I.GT.J) the operator ".GT." produces "true" if I has a greater signed value than J and produces "false" otherwise. In order to make the ALECS specifications easy to use, a set of operators similar to the FORTRAN operators have been implemented in ALECS. Note that ALECS converts these operators to proper assembly language instructions and puts them into the assembly language output file along with other code. As a shorthand notation, we use "L" as any general expression having a value of true or false. For the purposes of ALECS, false is defined as 0; any other value is true. The list below gives the allowed forms for L. Any other forms will produce ALECS errors. Also note that in the current context, "legal expression" means any expression legal in a PDP-11 MACRO-11 CMP or TST instruction or a VAX-11 MACRO CMPx or TSTx instruction. Note items in curly brackets {} are valid only for VAX-11 MACRO. 1. L may be any legal 16-bit-word expression. If byte {or longword} are used, the generated code still assumes 16-bit-words, perhaps giving execution-time errors. The expressions are interpreted as false if equal zero and true otherwise, e.g., IF( V.L(R0) ) CLR R0 WHEN ( D!F ) Page 30 2. L may be a simple "arithmetic" comparison of the form A:aop:B where A and B are any legal signed-word expressions and :aop: is one of :EQ:, :NE:, :LT:, :GT:, :LE:, or :GE:, e.g., UNLESS( (R0)+ :EQ: (R1)+ ) CLR (R0) Warning: spaces are illegal between paired colons! 3. The operators in item 2 may be forced to other than signed-word by appending the following strings: _W -- evaluate as 16-bit-word expression (DEFAULT) _B -- evaluate as byte expression _L -- evaluate as 32-bit-longword expression {VAX only} _S -- evaluate as signed expression (DEFAULT) _U -- evaluate as unsigned expression Only one of _W, {_L}, or _B may appear in any L. Only one of _S and _U may appear in any L. However, one each from the two groups may appear in an L together in any order but with only one underscore, e.g., IF( A :LE_U: R0) --word, unsigned IF( A :LE_SB: R0 ) --byte, signed IF( A :LE_WU: R0 ) --word, unsigned Note that _S and _U are legal for :EQ: and :NE: but have no effect. 4. L may be a condition code x=C, V, N or Z expressed as :x.SET: --> true if x bit set :x.CLR: --> true if x bit is clear For example, IF(:C.SET:) HALT 5. L is a bitwise comparison of two expressions in the format A:SET.IN:B --> true if "BIT A,B" is nonzero A:CLR.IN:B --> true if "BIT A,B" is zero Note byte {or longword} may be chosen by, e.g., :SET.IN_B:. The _S and _U are allowed but have no effect. 6. L may be a simple "logical" comparison of the form A:lop:B where A and B are any legal word expressions and :lop: is either :AND: or :IOR:. A and B are interpreted as false if equal to zero and true otherwise, e.g., WHILE( A(R3):AND:TIP) Page 31 Note all of the modifiers in item 3 are illegal for lop. 7. L is a compound logical expression of the form Lsl:lop:Ls2 where Ls is any of the above except 6, e.g., A:AND:B :IOR: R0 is illegal since Lsl is a "logical" comparison. :C.SET: :IOR: A:GT_B:B is legal. A:NE_B:B :AND: F:GT_BU:G is legal. Note all of the modifiers in item 3 are illegal for lop. Note parentheses for grouping are illegal; evaluation is strictly left to right. See Sec. 8.3 for some forms that are illegal. _____ _______ __________ 8.2 ALECS Control Structures All of the control structures listed in Sec. 4 of FLECS are supported in ALECS except DO. (It is not yet clear if DO is useful in assembly language or how it should be implemented. For example, should it be an SOB loop?) As in FLECS, assembly language code in the input file is passed to the output file. Only ALECS control structures are processed. Refer to an output assembly language file to find out what the actual code expansions for each construct are (but note the expansions may change with future releases of ALECS). Some examples of possible ALECS code are listed below: DIR$ #VREC ; GET A MESSAGE WHILE (:C.CLR:) . SELECT (FCT) ; FCT=FUNCTION CODE . . (#1) SHOW-PLOT . . (#2) ABORT-PLOT . . (OTHERWISE) MOV #1,ERR ; ILLEGAL CODE . ...FIN . SDRQ$S #RSBUF,,,,,#ERR ; RETURN STATUS . DIR$ #VREC ; GET NEXT MESSAGE ...FIN WHEN (PLTDFN :GE_BU: #4) MOV #5,ERR ELSE START-PLOT MOV #MSG,R1 ; ADDR OF BUFFER MOV #LEN,R2 ; LENGTH MOV #SAVE,R0 ; ADDR OF STORAGE UNTIL (R2 :LE: #0) . MOV (R1)+,(R0)+ . DEC R2 ...FIN IF (TTN :NE_B: PTT(R3)) ; NEW TT? . MOVB PPT(R3),TTN ; YES, SAVE # Page 32 . MOVB TTN,R0 ; SET UP ALUN$ . ALUN$S #LUN,#"TT,R0 ; ASSIGN LUN ...FIN Page 33 _____ ____________ ___ _____ 8.3 ALECS Restrictions and Notes The following restrictions and notes apply to the current version of ALECS: 1. Restrictions 4, 5, 7, and 8 in Sec. 6.0 also apply to ALECS. 2. ALECS must generate a number of labels. It does so by using symbols of the form "Innnnn:" where nnnnn is a 5-digit number. Do not use such labels! 3. Do not put blanks inside paired colons for ALECS operators, as this will cause fatal translation errors. For example, "IF(A:LE _U:B)" is illegal, but "IF(A :LE_U: B)" is legal. 4. In scanning specifications, ALECS assumes any colon is a delimiter for an ALECS operator. Thus, literal colons must not be put in ALECS specificaions. Incorrect Usage: Corrected Usage: IF(ICHAR:EQ_B:#':) COLON=72 IF(ICHAR:EQ_B:#COLON) 5. The code generated by ALECS uses branch instructions rather than jumps. Thus, assembly-time errors may result for long scopes. To avoid such problems, use procedure invocations. For example: CONDITIONAL . (R0:GT:R1) PROCESS-NORMAL-CASE . (R0:EQ:R1) PROCESS-NULL-CASE . (OTHERWISE) REPORT-ERROR ...FIN 6. The code generated by ALECS creates a label on all ALECS lines. Thus, local symbol blocks will be terminated by ALECS lines (unless the user has disabled local symbol blocks). 7. Labels on ALECS statements will cause the ALECS processor to assume the statement is pure assembly language, causing many assembly-time errors. Thus, if a label is necessary, put it on the line before the ALECS statement. For example: START: WHEN ((R5):LT:#3) 8. The SELECT statement assumes its arguments are 16-bit-word expressions, and there is no way to force other types. If byte {or longword} arguments are used, neither ALECS nor the assembler will detect an error; the code will simply Page 34 execute wrong. If types other than 16-bit-word are needed, use a CONDITIONAL instead of a SELECT. 9. For the logical operators :AND: and :IOR:, the second clause may or may not be evaluated at execution time depending on the value of the first clause. For example, in: WHEN (I:GT:J :AND: I:LT:R0) I will not be compared to R0 if I is less than or equal to J. Thus, code must not be written that depends on both clauses being executed. This has especially serious impact if the second clause uses autoincrement or decrement mode or if the first line of the scope expects to use condition codes set by the second clause. 10. Condition codes tested as the second clause of a logical are those set by the first clause! For example, in: IF( R0:GT:R1 :IOR: :Z.SET: ) :Z.SET: will be true if and only if R0=R1! Use of such a construct will result in a fatal translation error. Note, however, IF( :Z.SET: :IOR: R0:GT:R1 ) is legal. 11. A statement of the form IF( B :AND: A:GT:C ) is ambiguous. Does it mean (B:AND:A):GT:C or B:AND:(A:GT:C)? Since ALECS cannot determine the correct grouping, this type of statement is declared to be a fatal translation error. Note that ( A:GT:C :AND: B) is also illegal. 12. In general, autoincrement and autodecrement modes should be avoided inside ALECS specifications (see item 9). Exactly when and where the increment/decrement occurs depends sensitively on exactly how ALECS expands the specification into assembly language code. Since future releases may modify the code expansion, these modes are unsafe for use. Page 35 13. Blanks may be used outside of ALECS operators to make the listings and sources more readable. For example: WHEN(:C.SET::AND:(R0):GT:2(R3)) may be improved greatly with spaces: WHEN( :C.SET: :AND: (R0):GT:2(R3) ) 14. Procedure calls are implemented via a JSR {JSB} instruction. Thus, on entry to a procedure, there will be one {or more} extra word on the stack. On exit from the procedure, the information is removed from the stack by an RTS {RSB}. 15. Never JMP or BR out of a procedure, since the extra word put on the stack (see Item 14) will not be removed. | | 16. The .IMPLICIT NONE directive is not implemented in ALECS. | Using it in ALECS will give an assembler error. Page 36 9 FLECS DIRECTIVES FLECS/ALECS directives are used to force the translator to take nonstandard actions. Except for the "no translation flag," a directive consists of a period in column 7 followed by the directive name and, in some cases, a space followed by parameters. The defined directives are listed in the following subsections. __ ___________ ____ 9.1 No Translation Flag If a "#" is in column one of input to FLECS/ALECS, the line is not translated but is passed onto the FORTRAN/MACRO file (with the "#" replaced by a space). This will be of little use except when you intermix FORTRAN77 code with FLECS (e.g., to force FLECS to leave the FORTRAN77 ELSE statement alone). _____ _________ 9.2 .PAGE Directive .PAGE operates like the MACRO .PAGE directive. When the ___ directive is encountered, the listing file goes to a new page, and the .PAGE line is output as a comment line. Normally, the .PAGE directive has no effect on the FORTRAN/MACRO output file. However, if the /FUll switch is used in the FLECS/ALECS command line (see Sec. 10), a line is put into the output file to force a new page in the FORTRAN/MACRO output listing file (for FLECS, a formfeed is put in the file; for ALECS, .PAGE is put in the file). The syntax of .PAGE is .PAGE The directive may appear anywhere in the input file including between procedure definitions. _____ _________ 9.3 .NAME Directive The .NAME directive may be used to put a descriptive title into the second line of each page header in the FLECS/ALECS listing file. For example, this might be used to indicate which subroutine is on the page. The syntax is .NAME name where "name" is a 0-6 character ASCII string. (If no characters are given, the name field in the header is blanked out.) The name is used on the next new page, so to get the name on the "current" page, you must .NAME name .PAGE Page 37 To get the name on the first page of output, just putting the directive as the first line in the file is sufficient (the .PAGE is not necessary). ________ _________ 9.4 .INCLUDE Directive This directive is intended to operate much like the FORTRAN INCLUDE statement. The .INCLUDE directive specifies that the contents of a designated file are to be incorporated in the FLECS/ALECS translation directly following the .INCLUDE directive. It has no effect on program execution except to direct the translator to read input from a file. The .INCLUDE directive has the following syntax: .INCLUDE FILESPEC[/[-]LIST] where FILESPEC is the name of the file to be included in the translation. Note that, unlike the FORTRAN INCLUDE statement, the file specifier is not in apostrophes. The optional /[-]LIST switch may be used to force or prevent listing of the included file in the .FLL/.ALL file. If the switch is not given, the included file is listed. In the FLECS/ALECS listing files, the included lines are denoted by an * preceding the line number in the leftmost column. When the translator encounters a .INCLUDE directive, it stops reading statements from the current file and reads the statements in the included file. When it reaches the end of the included file, the translator resumes translation with the next statement after the .INCLUDE directive. A .INCLUDE directive can be contained in an included file. However, the maximum nesting depth of .INCLUDE statements is three. An included file can begin with a FORTRAN continuation line, but this use is probably unwise. The .INCLUDE directive can appear anywhere that a comment line can appear. Any FORTRAN/MACRO FLECS/ALECS can appear in an included file. However, the included statements, when combined with the other statements in the input, must satisfy the requirements of FLECS/ALECS and FORTRAN/MACRO (e.g., WHENs must have ELSEs, specification statements must precede executable statements, etc.). Page 38 ___________ ___________ __________ 9.5 Conditional Translation Directives These directives are used to control what code is put into the output FORTRAN/MACRO file. An example of the use of these directives is code that has common source for VMS/RSX using VMS system services and RSX executive directives. One might attempt to write such code using WHEN/ELSE: WHEN (variable that is .TRUE. if under VMS) . call system services ...FIN ELSE . call executive directives ...FIN However, the code would not compile under RSX (system service names are illegal there) and would not link under VMS (missing executive directive subroutines). The FLECS/ALECS conditional translation directives solve the problem as follows: .PASSIF VMS system service calls .PASSEND .PASSUNLESS VMS executive directive calls .passend If the symbol VMS were defined from the FLECS/ALECS command line (see below), only the code inside the first clause is translated and passed to the output FORTRAN/MACRO file. If the symbol is not defined, only code inside the second clause is passed to the output file. The syntax for the conditionals is .PASSIF symbol FLECS/FORTRAN or ALECS/MACRO code .PASSEND or .PASSUNLESS symbol FLECS/FORTRAN or ALECS/MACRO code .PASSEND Here "symbol" is an ASCII string 1-6 characters long. In the first case, the code will be put in the output FORTRAN/MACRO file if the symbol is defined; in the second case, the code will be put in the output if the symbol is not defined. Symbols are defined using the /COnditional switch in the FLECS/ALECS command line. The switch must be given on the input side of the line and has the format FLE>A,A=A/CO:n1:...:nm Page 39 where the ni's are 1-6 character ASCII symbols. If a symbol is given in the command line, the corresponding symbol is defined; if a symbol is not given, the symbol is not defined, e.g., for FLE>CALC,CALC=CALC/CO:VMS:NOBOX:ACQUISITION VMS, NOBOX, and ACQUIS are defined. (Long names are truncated to six characters.) The negated switch (/-CO) is illegal. Only input lines that are passed on to the FTN/MAC file are listed in the FLL/ALL file. However, all .PASSx lines are listed to show what conditionals are being used. Note that the line numbers in the left column of the FLL/ALL file will be discontinuous to reflect the fact that lines in the input FLX/ALX file were not passed to the FTN/MAC file. | | | _________ ____ _________ | 9.6 .IMPLICIT NONE Directive | | This FLECS* directive is used in place of the FORTRAN-77 | IMPLICIT NONE statement to make any undeclared variables an error. | (The FORTRAN IMPLICIT NONE statement would make variables generated | by FLECS errors!) Insert the directive in your code before any code | or variable declarations. | | Under VMS the directive generates code like | | IMPLICIT NONE | INCLUDE '32766.FID/NOLIST' | | so that any undeclared variable will cause a FORTRAN error. The | FID file (FLECS Internal Declarations) contains declarations for | all variables generated by FLECS for the routine. If | USER$COM:FLE.COM is used (see Sec. 10) the FID files are | automatically deleted after compilation completes successfully. | | Under RSX FORTRAN-77 the IMPLICIT NONE statement is not | supported. In this case the directive generates code like | | IMPLICIT COMPLEX (A-Z) | INCLUDE '32766.FID/NOLIST' | | so that any undeclared variable will be typed COMPLEX*8. The | FORTRAN compiler will flag use of such variables an error in some | cases; to find all such uses, however, you must look in the FORTRAN | variable map for C*8 variables. If [202,1]FLE.COM is used (see | Sec. 10) the FID files are automatically deleted after compilation | | ---------- | | *This directive is not implemented for ALECS. Use of the directive in | ALECS will give an assemly-time error. Page 40 | completes successfully. Page 41 10 PROCEDURE FOR USE Under RSX-11M the FLECS and ALECS translators must be | installed in the system. Assuming the files FLE.TSK and ALE.TSK | are on DP1: under UIC [201,7], the procedure is: MCR>HEL SYSTEM/password | MCR>INS DP1:[201,7]FLE/TASK=...FLE | MCR>INS DP1:[201,7]ALE/TASK=...ALE | Under VMS the system manager must put files FLE.EXE and | ALE.EXE in directory [SYSEXE] so that they may be invoked by | | $ MCR FLE or | | $ MCR ALE | To invoke the FLECS translator for RSX-11M or VMS: MCR>FLE OUT/[-]FU,LIST/[-]SP=IN/CO:N1:...:NM 1. OUT is an output file specifier to receive the generated FORTRAN file; if an extension is not given, FTN is assumed. The OUT file is optional--if not given, the file is not produced; however, the comma must be given. The /FU switch, if given, produces a "full" output--comments in the input file are put in the output along with FLECS structured statements as comments. If /-FU is given or if the switch is not given, only generated FORTRAN is put in OUT. 2. LIST is an output file specifier to receive the FLECS listing file; if an extension is not given, FLL is assumed. The LIST file is optional--if not given, the file is not produced (the comma should not be given in this case). The /SP switch if explicitly given or if omitted causes the LIST file to be spooled to the line printer and deleted. If /-SP is given, the LIST file is neither put on the line printer nor is it deleted. 3. IN is an input file specifier for the FLECS input; if an extension is not given, FLX is assumed. This specifier must be given. See Sec. 9 for a description of the /CO switch. To invoke the ALECS translator for RSX-11M or VMS: MCR>ALE OUT/[-]FU,LIST/[-]SP=IN/CO:N1:...:NM All comments for the FLECS line apply except that the default extensions are MAC, ALL, and ALX, respectively. Page 42 Probably the simplest way to use FLECS or ALECS is to create a command file in the following form: .MORE: .ASKS NAM GIVE NAME OF FILE FLE 'NAM','NAM'/-SP='NAM' F77 'NAM','NAM'/-SP='NAM' PIP 'NAM'.FLL='NAM'.LST/AP PIP 'NAM'.FTN;*,'NAM'.LST;*/DE .GOTO MORE The procedure will continue to ask for source files until a CTRL/Z is given to the question. (Note that the two PIP steps may be replaced with program AFF for FLECS.) Standard versions of command files are available for both RSX-11M and VMS. The files may be found in directory [202,1] for RSX-11M and USER$COM for VMS. The command files may be used by @[dir]FLE NAME FORSW FLESW @[dir]ALE NAME MACSW ALESW where NAME is the name of the .FLX/.ALX file given without a file extension or version number, eg. MYFILE or DRA0:[A.B.C]SOURCE FORSW/MACSW is any FORTRAN/MACRO switches to be used when the file is compiled, eg. /CO:19. If no FORTRAN/MACRO switches are desired, but you will be giving FLECS/ALECS switches, put a pound sign (#) in this position. FLESW/ALESW is any FLECS/ALECS switches to be used (may be blank). Examples of proper calls to the command procedures are: @FLE XYZ /CO:19 /FU @FLE XYZ # /FU !No FORTRAN Switches @FLE XYZ /CO:19 !No FLECS Switches @FLE XYZ !No switches @FLE !File will prompt for information FLECS and ALECS "EXIT WITH STATUS" so that under RSX-11M the symbol may be checked in the command procedure to determine if FORTRAN, etc., should be called. {Use symbol $STATUS in VMS.} When FLECS/ALECS is given a command line, it first verifies the command line is correct before attempting to carry out the translation. During this verification, an error message may be Page 43 output describing the error in the line. In this case, no translation is done. The form of the error message is xxx SPECIFIER ERROR--COMMAND IGNORED where xxx is one of the four strings below: 1. CSI--The gross structure of the command line is incorrect, e.g., there are two equal signs in the line. 2. FTN--The OUT file specifier for the FTN file is incorrect (e.g., a four-letter extension), or an illegal switch has been used (only /FU or /-FU are allowed with the FTN file), or there is no space left on the disk for the file. 3. FLL--The LIST file specifier for the FLL file is incorrect, or an illegal switch has been used (only /SP or /-SP are allowed with the FLL file), or there is no space left on the disk for the file. 4. FLX--The IN file specifier for the FLX file is incorrect, or an illegal switch has been used (only /CO is allowed with the FLX file), or the named file does not exist. The LAMPF version of FLECS and ALECS have a nonstandard extension: comments are allowed on structured statement lines. For FLECS, such comments must be preceded by an exclamation point; for ALECS, such comments must be preceded by a semicolon. Examples: WHEN(I.GT.J) ! ONLY OCCURS FOR BAD DATA REPEAT UNTIL(:C.SET:) ; QUIT ON ERROR DO(I=1,NTERM) ! NTERM=POLYNOMIAL DEGREE This capability is available in standard FLECS (if FORTRAN allows such comments) and ALECS for one-line structured statements, e.g., WHEN (I.GT.J)I=0 ! ONLY OCCURS FOR BAD DATA REPEAT UNTIL(:C.SET:) DIR$ #V; QUIT ON ERROR The extension is to provide the capability for the multiline form. Note that the in-line comment allows a convenient way of sorting out FINs: WHILE(I.GT.J) . IF(L) . . DO(M=1,500) . . . etc. . . ...FIN!DO . ...FIN!IF ...FIN!WHILE APPENDIX A FLOW CHARTS FOR FLECS STATEMENTS LEGEND: [L] = Logical Expression $ = Statement(s) [EL] = Expression I@ = DO specification IF ( [L] ) $ UNLESS ( [L] ) $ WHEN ( [L] ) $1 ELSE $2 ------------- ------------------ ---------------- ! ! ! / \ T / \ F / \ T <[L]>----->$ <[L]>----->$ <[L]>---->$1 \./ ! \./ ! \./ ! ! ! ! ! ! ! F! ! T! ! F! ! ! ! ! ! $2 ! !--------' !--------' !--------' ! ! ! REPEAT UNTIL ( [L] ) $ REPEAT WHILE ( [L] ) $ ------------------------ ------------------------ ! ! !<-----. !<-----. ! ! ! ! $ ! $ ! ! ! ! ! / \ F ! / \ T ! <[L]>----' <[L]>----' \./ \./ ! ! T! F! FLOW CHARTS FOR FLECS STATEMENTS Page A-2 UNTIL ( [L] ) $ WHILE ( [L] ) $ ----------------- ----------------- ! ! !<-----. !<-----. ! ! ! ! T / \ ! F / \ ! .--<[L]> ! .--<[L]> ! ! \./ ! ! \./ ! ! ! ! ! ! ! ! F! ! ! T! ! ! '---$--' ! '---$--' ! ! ----. ----. ! ! CONDITIONAL SELECT ( [EL] ) . ( [L1] ) $1 . ( [EL1] ) $1 . ( [L2] ) $2 . ( [EL2] ) $2 . . . . . . . ( [Ln] ) $n . ( [ELn] ) $n ...FIN ...FIN --------------------- ------------------- ! ! / \ / \ / \ T /[EL]\ T <[L1] >----->$1-. <=[EL1]>----->$1-. \ / ! \ / ! \./ ! \./ ! F! ! F! ! ! ! ! ! / \ ! / \ ! / \ T ! /[EL]\ T ! <[L2] >----->$2-! <=[EL2]>----->$2-! \ / ! \ / ! \./ ! \./ ! F! ! F! ! ! ! ! ! ! ! ! ! / \ ! / \ ! / \ T ! /[EL]\ T ! <[Ln] >-----$n--! <=[ELn]>-----$n--! \ / ! \ / ! \./ ! \./ ! F! ! F! ! !------------' !-------------' ! ! Note: OTHERWISE can be used as a catchall condition in CONDITIONAL and SELECT statements. FLOW CHARTS FOR FLECS STATEMENTS Page A-3 -------------------------- --------------------- CARRY-OUT-ACTION DO (I@) $ TO CARRY-OUT-ACTION $ --------------------- -------------------------- Note: Place a RETURN, STOP, or CALL EXIT statement ahead of the first TO statement. APPENDIX B AVAILABLE DOCUMENTATION CONCERNING FLECS (December, 1974) Beyer, T.: FLECS Users Manual (University of Oregon Edition) Contains a concise description of the FLECS extension of FORTRAN and of the details necessary to running a FLECS program on the PDP-10 or the IBM s/360 at Oregon. This is the original manual on which this one is based. Beyer, T.: FLECS: System Modification Guide Contains 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 improve the efficiency of the system by rewriting portions of the system in assembly language. INDEX Page Index-1 INDEX #, 36 Keywords, 8, 24, 27 *, 37 {}, 29 Line numbers, 6 Listing, 11 ALE, 41 Logical expression, 13 ALECS, 29 Loops, 16 ALECS control structures, 31 ALECS operators, 29 Multiline structured statement, 8 Blanks, 23 .NAME, 36 Nesting, 9 Command procedure, 42 No Translation Flag, 36 Comment line, 12 Comments, 43 One-line structured statement, 9 Comments in-line, 43 OTHERWISE, 15 to 16 CONDITIONAL, 15 Conditional translation, 38 .PAGE, 36 Context errors, 26 Parentheses, 24, 27 Continuation lines, 23 .PASSEND, 38 Control phrase, 8 .PASSIF, 38 Control structures, 13 .PASSUNLESS, 38 Curly brackets, 29 Procedure name, 20 Decision structures, 13 REPEAT UNTIL, 19 Directives, 36 REPEAT WHILE, 18 DO, 8, 17 Restrictions, 23, 33 Errors, 26 Scope, 8 Extended statement, 5 SELECT, 16 Simple statement, 8 False, 29 Source preparation, 11 FIN, 8 Specification, 8 FLE, 41 Statement number, 23 FLECS Directives, 36 Structured statement, 8 FORTRAN features, 5 Syntax errors, 26 Hollerith, 24 Transportability, 5 True, 29 IF, 8, 13 .IMPLICIT NONE, 39 Undetected errors, 27 In-line comments, 43 UNLESS, 13 .INCLUDE, 37 UNTIL, 18 Indentation, 11, 23 Integer variable, 23 WHEN...ELSE, 14 Internal procedures, 20 WHILE, 17