DOCUMENT MP-1-3415 File: MPFG0::DRA0:[MP1Q.FLECS]FLECSUIM.RNO FLECS and ALECS User's Manual This manual corresponds to version 22 of FLECS As Modified at LAMPF October 31, 1982 GROUP MP-1 Clinton P. Anderson Meson Physics Facility (LAMPF) Los Alamos National Laboratory Los Alamos, New Mexico 87545 Page 2 TABLE OF CONTENTS 1.0 INTRODUCTION . . . . . . . . . . . . . . . . . . . . 5 1.1 Retention Of FORTRAN Features . . . . . . . . . . 6 1.2 Correlation of FLECS and FORTRAN Sources . . . . . 6 2.0 STRUCTURED STATEMENTS . . . . . . . . . . . . . . . 7 3.0 INDENTATION, LINES, AND THE LISTING . . . . . . . 10 4.0 CONTROL STRUCTURES . . . . . . . . . . . . . . . . 12 4.1 Decision Structures . . . . . . . . . . . . . . 12 4.1.1 IF . . . . . . . . . . . . . . . . . . . . . . 12 4.1.2 UNLESS . . . . . . . . . . . . . . . . . . . . 12 4.1.3 WHEN...ELSE . . . . . . . . . . . . . . . . . 13 4.1.4 CONDITIONAL . . . . . . . . . . . . . . . . . 14 4.1.5 SELECT . . . . . . . . . . . . . . . . . . . . 15 4.2 Loop Structures . . . . . . . . . . . . . . . . 15 4.2.1 DO . . . . . . . . . . . . . . . . . . . . . . 16 4.2.2 WHILE . . . . . . . . . . . . . . . . . . . . 16 4.2.3 REPEAT WHILE . . . . . . . . . . . . . . . . . 17 4.2.4 UNTIL . . . . . . . . . . . . . . . . . . . . 17 4.2.5 REPEAT UNTIL . . . . . . . . . . . . . . . . . 18 5.0 INTERNAL PROCEDURES . . . . . . . . . . . . . . . 19 6.0 RESTRICTIONS AND NOTES . . . . . . . . . . . . . . 22 7.0 ERRORS . . . . . . . . . . . . . . . . . . . . . . 24 7.1 Syntax Errors . . . . . . . . . . . . . . . . . 24 7.2 Context Errors . . . . . . . . . . . . . . . . . 24 7.3 Undetected Errors . . . . . . . . . . . . . . . 25 7.4 Other Errors . . . . . . . . . . . . . . . . . . 26 8.0 ALECS - FLECS FOR ASSEMBLY LANGUAGE ROUTINES . . . 27 8.1 ALECS Operators . . . . . . . . . . . . . . . . 27 8.2 ALECS Control Structures . . . . . . . . . . . . 29 8.3 ALECS Restrictions and Notes . . . . . . . . . . 30 9.0 FLECS DIRECTIVES . . . . . . . . . . . . . . . . . 33 9.1 No Translation Flag . . . . . . . . . . . . . . 33 9.2 .PAGE Directive . . . . . . . . . . . . . . . . 33 9.3 .NAME Directive . . . . . . . . . . . . . . . . 33 9.4 .INCLUDE Directive . . . . . . . . . . . . . . . 34 9.5 Conditional Translation Directives . . . . . . . 35 Page 3 10.0 PROCEDURE FOR USE . . . . . . . . . . . . . . . . 37 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. Page 5 1.0 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 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. Page 6 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 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 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. (The FLECS line number is to the left of the statement in the FLECS listing file.) 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. Page 7 2.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 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 8 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 9 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 10 3.0 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 11 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 12 4.0 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 13 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 14 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 15 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 16 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 17 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 18 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 19 5.0 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 Page 20 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., 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 21 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 22 6.0 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. 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 ______ __________ ____ _____ __ __________ _______ statement would be acceptable. Don't put them between the _________ _____ __ __________ end of a WHEN statement and the beginning of an ELSE Page 23 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 and the END statement. Page 24 7.0 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 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 25 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. Page 26 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 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 _____ ______ 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 27 8.0 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 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 MACRO-11 CMP or TST instruction. 1. L may be any legal word expression. Byte is not allowed. The expressions are interpreted as false if equal zero and true otherwise, e.g., IF( V.L(R0) ) CLR R0 WHEN ( D!F ) 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! Page 28 3. The operators in item 2 may be forced to other than signed-word by appending the following strings: _W -- evaluate as word expression (DEFAULT) _B -- evaluate as byte expression _S -- evaluate as signed expression (DEFAULT) _U -- evaluate as unsigned expression Only one of _W and _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 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) 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. Page 29 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. 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 # . MOVB TTN,R0 ; SET UP ALUN$ . ALUN$S #LUN,#"TT,R0 ; ASSIGN LUN ...FIN Page 30 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 word expressions, and there is no way to force other types. If byte arguments are used, neither ALECS nor the assembler will detect an error; the code will simply execute wrong. Page 31 If types other than 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 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 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 32 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 instruction. Thus, on entry to a procedure, there will be one extra word on the stack. On exit from the procedure, the extra word is removed by an RTS. 15. Never JMP or BR out of a procedure, since the extra word put on the stack (see Item 14) will not be removed. Page 33 9.0 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 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 34 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 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, and the /[-]LIST switch is not allowed. 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 35 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 whould 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 36 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 VMX, 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. Page 37 10.0 PROCEDURE FOR USE The FLECS and ALECS translators must be installed in the system. Assuming the file FLE.TSK is on DP1: under UIC [12,1], the procedure is: MCR>HEL [10,10] MCR>INS DP1:[12,1]FLE/TASK=...FLE MCR>INS DP1:[12,1]FLE/TASK=...ALE To invoke the FLECS translator: 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: 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 38 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' F4P '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.) Under 11M, FLECS and ALECS "EXIT WITH STATUS" so that the symbol may be checked in the command procedure to determine if F4P, etc., should be called. 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 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 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 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 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. Page 39 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 #, 33 Logical expression, 12 *, 34 Loops, 15 .INCLUDE, 34 .NAME, 33 Multiline structured statement, .PAGE, 33 7 .PASSEND, 35 .PASSIF, 35 Nesting, 8 .PASSUNLESS, 35 No Translation Flag, 33 ALE, 37 One-line structured statement, 8 ALECS, 27 OTHERWISE, 14-15 ALECS control structures, 29 ALECS operators, 27 Parentheses, 23, 26 Procedure name, 19 Blanks, 22 REPEAT UNTIL, 18 Command procedure, 38 REPEAT WHILE, 17 Comment line, 11 Restrictions, 22, 30 Comments, 39 Comments in-line, 39 Scope, 7 CONDITIONAL, 14 SELECT, 15 Conditional translation, 35 Simple statement, 7 Context errors, 24 Source preparation, 10 Continuation lines, 22 Specification, 7 Control phrase, 7 Statement number, 22 Control structures, 12 Structured statement, 7 Syntax errors, 24 Decision structures, 12 Directives, 33 Transportability, 5 DO, 7, 16 Undetected errors, 25 Errors, 24 UNLESS, 12 Extended statement, 6 UNTIL, 17 FIN, 7 WHEN...ELSE, 13 FLE, 37 WHILE, 16 FLECS Directives, 33 FORTRAN features, 6 Hollerith, 23 IF, 7, 12 In-line comments, 39 Indentation, 10, 22 Integer variable, 22 Internal procedures, 19 Keywords, 7, 23, 25 Line numbers, 6 Listing, 10