.!To create FLECS.MAN .! .! .R RUNOFF .! *FLECS.MAN=FLECS.RNM/CR/RI:8 .! .sp 1 .ps 58, 60 .st .lm 0 .rm 60 .fg 6 .c 60;F L E C S .s 3 .c 60;(&FORTRAN &Language with &Extended &Control &Structures) .s 3 .c 60;U S E R'S M A N U A L .s 6 .c 60;Versions 1 through 22 .c 60;Terry Beyer .c 60;University of Oregon .c 60;October 1, 1975 .s 2 .c 60;Civil Aeromedical Institute .c 60;January 17, 1979 .s 2 .c 60;Version 22H(126), RT-11 .c 60;Robert Carter .c 60;Princeton Gamma Tech .c 60;February 16, 1981 .s 2 .c 60;Version 22H(126), DECsystem-10 .c 60;Leland M. Bruns .c 60;Johnson _& Johnson .c 60;March 2, 1981 .nnm .pg .fg 12 .c 60;* * * N O T I C E * * * .S 2 ^&Disclaimer\&: .s 1 None of the authors nor their employers shall be libel in any way for any direct, indirect, incidental, consequential, or specific damages of any kind or from any cause whatsoever arising out of or in any way connected with the use or performance of this software. .s 2 ^&Permission\&: .s 1 This software is in the public domain and may be reproduced or altered without the explicit permission of the authors. .pg .fg 12 ^&Acknowledgements\&: .s 1 The author is indebted to many people for assistance of one form or another during the course of this project. Mike Dunlap, Kevin McCoy, and Peter Moulton deserve special thanks for many helpful and fruitful discussions, suggestions, and encouragements. I am grateful to my wife, Kathleen, who assisted in many ways including shielding me from the harsh reality of JCL and 360 Assembler Language. Text preparation was adroitly accomplished by Marva VanNatta, Allyene Tom, Diane Lane, and Kathleen Beyer. .s 1 This project was initiated while the author was working under a grant provided by the Office of Scientific and Scholarly Research of the Graduate School at the University of Oregon. Work on the project has also been supported in part by the Department of Computer Science and by the Computing Center of the University of Oregon. .s 1 .i 45;Terry Beyer .i 45;October 1, 1975 .nm .ch INTRODUCTION .LC .LM 0 .RM 60 ^F^O^R^T^R^A^N CONTAINS FOUR BASIC MECHANISMS FOR CONTROLLING PROGRAM FLOW: ^^CALL/RETURN, IF, DO\\, AND VARIOUS FORMS OF THE ^^GO TO\\. .S ^F^L^E^C^S, A LANGUAGE EXTENSION TO ^F^O^R^T^R^A^N, HAS ADDITIONAL CONTROL MECHANISMS THAT MAKE IT EASIER TO WRITE ^F^O^R^T^R^A^N BY ELIMINATING MUCH OF THE CLERICAL DETAIL ASSOCIATED WITH CONSTRUCTING ^F^O^R^T^R^A^N PROGRAMS. ^F^L^E^C^S IS ALSO EASIER TO READ AND COMPREHEND. .S ^THIS MANUAL IS A BRIEF BUT COMPLETE INTRODUCTION TO ^F^L^E^C^S. ^IT IS NOT A PRIMER ON ^F^L^E^C^S OR STRUCTURED PROGRAMMING. ^THE READER IS ASSUMED TO BE A KNOWLEDGEABLE ^F^O^R^T^R^A^N PROGRAMMER. .S ^PROGRAMMERS TO WHOM TRANSPORTABILITY OF THEIR PROGRAMS IS A .x TRANSPORTABILITY CONCERN SHOULD NOTE THAN THE ^F^L^E^C^S TRANSLATOR SOURCE CODE IS IN THE PUBLIC DOMAIN AND IS MADE FREELY AVAILABLE. ^THE TRANSLATOR WAS WRITTEN WITH TRANSPORTABILITY IN MIND AND REQUIRES LITTLE EFFORT TO MOVE FROM ONE MACHINE TO ANOTHER. ^THOSE INTERESTED IN MOVING ^F^L^E^C^S TO ANOTHER MACHINE OR HAVING THEIR OWN COPY OF ^F^L^E^C^S SHOULD CONTACT THE ^UNIVERSITY OF ^OREGON ^COMPUTING ^CENTER. .S ^AT ^OREGON, ^F^L^E^C^S IS IMPLEMENTED ON BOTH THE ^^DEC\\SYSTEM-10 AND THE .x ^^DEC\\SYSTEM-10 .x ^^IBM S/360\\ ^^IBM S/360\\. ^THE MANNER OF IMPLEMENTATION IS THAT OF A PREPROCESSOR THAT TRANSLATES ^F^L^E^C^S PROGRAMS INTO ^F^O^R^T^R^A^N PROGRAMS. ^THE RESULTING ^F^O^R^T^R^A^N PROGRAM IS THEN PROCESSED IN THE USUAL WAY. ^THE TRANSLATOR ALSO PRODUCES A NICELY FORMATTED LISTING OF THE ^F^L^E^C^S PROGRAM THAT GRAPHICALLY PRESENTS THE CONTROL STRUCTURES USED. .PG ^THE FOLLOWING DIAGRAM ILLUSTRATES THE TRANSLATING PROCESS. .S 2 .NF .UC .TEST PAGE 13 /-------/ +----------+ /----------/ +--------+ /FLECS / | FLECS | /Translated/ |FORTRAN | /Source /---->|Translator|---->/ FORTRAN /---->|Compiler| /Program/ | | / Source / | | /-------/ +----------+ /----------/ +--------+ | | V /---------/ / FLECS / / Indented/ / Listing/ /---------/ .F .LC .hl 1 ^RETENTION OF ^F^O^R^T^R^A^N ^FEATURES ^THE ^F^L^E^C^S TRANSLATOR EXAMINES EACH STATEMENT IN THE ^F^L^E^C^S .x ^F^O^R^T^R^A^N FEATURES PROGRAM TO SEE IF IT IS AN ^&EXTENDED STATEMENT\& (A STATEMENT .x EXTENDED STATEMENT VALID IN ^F^L^E^C^S BUT NOT IN ^F^O^R^T^R^A^N). ^IF IT IS RECOGNIZED AS AN EXTENDED STATEMENT, THE TRANSLATOR GENERATES THE CORRESPONDING ^F^O^R^T^R^A^N STATEMENTS. ^IF, HOWEVER, THE STATEMENT IS NOT RECOGNIZED AS AN EXTENDED STATEMENT, THE TRANSLATOR ASSUMES IT MUST BE A ^F^O^R^T^R^A^N STATEMENT AND PASSES IT THROUGH UNALTERED. ^THUS ^&THE ^F^L^E^C^S SYSTEM DOES NOT RESTRICT THE USE OF ^F^O^R^T^R^A^N STATEMENTS\&, IT SIMPLY PROVIDES ADDITIONAL STATEMENTS WHICH MAY BE USED. ^IN PARTICULAR, ^^GO TO\\S, ARITHMETIC ^^IF\\S, ^^CALL\\S, ARITHMETIC STATEMENT FUNCTIONS, AND ANY OTHER ^F^O^R^T^R^A^N STATEMENTS, COMPILER DEPENDENT OR OTHERWISE, MAY BE USED IN A ^F^L^E^C^S PROGRAM. .BR .hl 1 ^CORRELATION OF ^F^L^E^C^S AND ^F^O^R^T^R^A^N ^SOURCES .S ^ONE DIFFICULTY OF PREPROCESSOR SYSTEMS LIKE ^F^L^E^C^S IS THAT ERROR MESSAGES THAT COME FROM THE ^F^O^R^T^R^A^N COMPILER MUST BE RELATED BACK TO THE ORIGINAL ^F^L^E^C^S SOURCE PROGRAM. ^THIS DIFFICULTY IS REDUCED BY ALLOWING THE PLACEMENT OF ^&LINE NUMBERS\& (NOT TO BE CONFUSED .x LINE NUMBERS WITH ^F^O^R^T^R^A^N STATEMENT NUMBERS) ON ^F^L^E^C^S SOURCE STATEMENTS. ^THESE LINE NUMBERS THEN APPEAR ON THE LISTING AND IN THE ^F^O^R^T^R^A^N SOURCE. ^WHEN AN ERROR MESSAGE IS PRODUCED BY EITHER THE ^F^L^E^C^S TRANSLATOR OR THE ^F^O^R^T^R^A^N COMPILER, IT WILL INCLUDE THE LINE NUMBER OF THE OFFENDING ^F^L^E^C^S SOURCE STATEMENT, MAKING IT EASY TO LOCATE ON THE LISTING. .S ^IF THE PROGRAMMER CHOOSES NOT TO SUPPLY LINE NUMBERS, THE TRANSLATOR WILL ASSIGN SEQUENTIAL NUMBERS AND PLACE THEM ON THE LISTING AND IN THE ^F^O^R^T^R^A^N SOURCE. ^THUS, ERRORS FROM THE COMPILER MAY STILL BE RELATED TO THE ^F^L^E^C^S LISTING. .S ^DETAILS OF LINE NUMBERING ARE MACHINE DEPENDENT. ^ON MOST CARD-ORIENTED SYSTEMS, THE LINE NUMBERS MAY BE PLACED IN COLUMNS 76-80 OF EACH CARD. ^OTHER SYSTEMS MAY HAVE SPECIAL PROVISIONS FOR LINE NUMBERS. .S .uc On the DECsystem-10 SOS line sequence numbers are used .x ^D^E^Csystem-10 .x line sequence numbers>^S^O^S .x ^S^O^S>line sequence numbers by FLECS for line numbering whenever they are present on the input file. The line sequence increment between lines should be no less than 10 to assure that FLECS has sufficient "space" to generate the FORTRAN statement(s) corresponding to each FLECS statement. If there is insufficient room for the generated statements, or if the statement numbers from the input file are not in sequence, FLECS will renumber the FORTRAN output file from that point by 00001 until it is back in step with the input code (the line numbers on the listing file will remain unchanged). There are two exceptions to the sequence checking done by FLECS: line numbering may be restarted from any initial value at 1)#the beginning of a routine and 2)#the beginning of a page. .S .x ^D^E^C ^R^T-11 Under RT-11 (PDP-11 _& LSI-11) it is inconvenient for the user to create a line numbered file. Therefore the FLECS listing contains both sequential FLECS listing line numbers and computed FORTRAN line numbers which should correspond with the FORTRAN listing line numbers. (See the RT-11 implementation notes on how to optionally include numbering in the generated FORTRAN source code.) .s .lc ^THE BEGINNING ^F^L^E^C^S PROGRAMMER SHOULD DISCOVER AND MAKE SPECIAL NOTE OF THE DETAILS OF THE MECHANISM BY WHICH ^F^O^R^T^R^A^N COMPILER ERROR MESSAGES MAY BE TRACED BACK TO THE ^F^L^E^C^S LISTING ON THE SYSTEM BEING USED. .BR .ch STRUCTURED STATEMENTS .LC .LM 0 .RM 60 ^A BASIC NOTION OF ^F^L^E^C^S IS THAT OF THE ^&STRUCTURED STATEMENT\& WHICH CONSISTS OF A ^&CONTROL PHRASE\& AND ITS .x STRUCTURED STATEMENT .x CONTROL PHRASE .X SCOPE SCOPE. ^F^O^R^T^R^A^N HAS TWO STRUCTURED STATEMENTS, THE LOGICAL ^^IF\\ AND THE ^^DO\\. ^THE FOLLOWING EXAMPLE ILLUSTRATES THIS TERMINOLOGY: .x ^^IF\\ statement .x ^^DO\\ statement .NF .UC .S 2 .TEST PAGE 12 Structured Statement /_\ /--------------- ----------------_\ Control Phrase Scope /_\ /_\ /--------- ---------_\ /-- ---_\ Keyword Specification /_\ /_\ /- --_\ /---- -----_\ IF (X.EQ.Y) U = V + W .S 2 .TEST PAGE 9 Keyword Specification /_\ /_\ /- --_\ /---- -----_\ DO 30 I = 1, N > Control Phrase _\ A(I) = B(I) + C _\ _\ Structured L(I) = I - K(I) > Scope / Statement 30 CONTINUE / / .S 2 .F .LC ^NOTE THAT EACH STRUCTURED STATEMENT CONSISTS OF A CONTROL PHRASE .x 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 .x KEYWORDS SOME ADDITIONAL INFORMATION CALLED THE ^&SPECIFICATION\&. .x SPECIFICATION ^A STATEMENT THAT DOES NOT CONSIST OF A CONTROL PHRASE AND A SCOPE IS SAID TO BE A ^&SIMPLE STATEMENT\&. .x SIMPLE STATEMENT ^EXAMPLES OF SIMPLE STATEMENTS ARE ASSIGNMENT STATEMENTS, SUBROUTINE ^^CALL\\S, ARITHMETIC ^^IF\\S, AND ^^GO TO\\S. .S ^THE PROBLEM WITH THE ^F^O^R^T^R^A^N 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 ^D^O SPECIFICATION IS NOT. .S ^IN ^F^L^E^C^S 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. ^THE STATEMENTS COMPOSING THE SCOPE ARE PLACED ON SUCCESSIVE LINES. ^THE END OF THE SCOPE IS INDICATED BY A ^^FIN\\ STATEMENT. .x ^^FIN\\ statement ^THIS CREATES A ^&MULTI-LINE STRUCTURED STATEMENT\&. .x MULTI-LINE STRUCTURED STATEMENT ^EXAMPLES OF MULTI-LINE STRUCTURED STATEMENTS: .S .NF .TEST PAGE 10 ^^IF (X.EQ.Y) . U = V+W . R = S+T ...FIN\\ .S ^^DO (I=1,N) . A(I) = B(I)+C . C = C*2.14-3.14 ...FIN\\ .S 2 .F .LM 8 .RM 52 ^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\\. .LM 0 .RM 60 .S 2 ^NESTING OF STRUCTURED STATEMENTS IS PERMITTED TO ANY DEPTH. .x NESTING .S ^EXAMPLE OF NESTED STRUCTURED STATEMENTS: .S .NF .TEST PAGE 8 ^^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\\ .S 2 .F ^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\&. .x ONE-LINE STRUCTURED STATEMENT .S .TP 5 ^EXAMPLES OF ONE-LINE STRUCTURED STATEMENTS: .S .NF ^^IF (X.EQ.Y) U=V+W\\ .S ^^DO (I=1,N) A(I) = B(I)+C\\ .S .F ^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. .S ^EXAMPLE OF INVALID CONSTRUCTION: .S .NF ^^IF (X.EQ.Y) DO (I=1,N) A(I) = B(I)+C\\ .S .F ^TO ACHIEVE THE EFFECT DESIRED ABOVE, THE ^^IF\\ MUST BE WRITTEN IN A MULTI-LINE FORM. .S ^EXAMPLE OF VALID CONSTRUCTION: .S .NF ^^IF (X.EQ.Y) . DO (I=1,N) A(I) = B(I)+C ...FIN\\ .S .F ^F^L^E^C^S PROVIDES, IN ADDITION TO ^^IF\\ AND ^^DO\\, SEVERAL USEFUL STRUCTURED STATEMENTS NOT AVAILABLE IN ^F^O^R^T^R^A^N. ^AFTER A BRIEF EXCURSION INTO THE SUBJECT OF INDENTATION, WE WILL PRESENT THESE ADDITIONAL STRUCTURES. .BR .ch INDENTATION, LINES, AND THE LISTING FILE .LC .LM 0 .RM 60 ^IN THE EXAMPLES OF MULTI-LINE STRUCTURED STATEMENTS, THE STATEMENTS IN THE SCOPE WERE INDENTED AND AN ^L-SHAPED .x INDENTATION LINE WAS DRAWN (IN DOTS) 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 ^^FIN\\S ARE QUITE SIMPLE AND UNIFORM. ^THE CONTROL PHRASE OF A MULTI-LINE STRUCTURED STATEMENT ALWAYS CAUSES INDENTATION OF THE STATEMENTS THAT FOLLOW. ^NOTHING ELSE CAUSES INDENTATION. ^A LEVEL OF INDENTATION (I.E. A SCOPE) IS ALWAYS TERMINATED BY A ^^FIN\\. ^NOTHING ELSE TERMINATES A LEVEL OF INDENTATION. .hl 1 ^PREPARATION OF ^F^L^E^C^S ^SOURCE ^FILES ^WHEN WRITING A ^F^L^E^C^S PROGRAM ON PAPER, THE PROGRAMMER SHOULD ADOPT THE INDENTATION AND LINE-DRAWING CONVENTIONS SHOWN IN .x SOURCE PREPARATION ^F^L^E^C^S LISTINGS. ^WHEN PREPARING A ^F^L^E^C^S SOURCE PROGRAM IN MACHINE-READABLE FORM, HOWEVER, EACH STATEMENT SHOULD BEGIN IN COLUMN 7. (^THE ^^FLECS\\ IMPLEMENTATIONS ON THE ^D^E^CSYSTEM-10 AND UNDER ^R^T-11 .x ^D^E^Csystem-10 .x ^D^E^C ^R^T-11 WILL ALSO ACCEPT ^^FLECS\\ STATEMENTS BEGINNING IMMEDIATELY AFTER ANY TAB CHARACTER IN COLUMNS 1 THROUGH 6 IN THE SAME MANNER AS IS .x tabs VALID FOR THE ^^FORTRAN\\ COMPILERS FOR THOSE SYSTEMS.) .x ^F^O^R^T^R^A^N-10 ^WHEN THE ^F^L^E^C^S 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. .x LISTING .S .TP 12 ^EXAMPLE OF INDENTATION: .S .NF 1. ^PROGRAM AS ENTERED INTO COMPUTER. .S .TEST PAGE 8 ##^^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\\ .S .TP 10 2. ^PROGRAM AS LISTED BY ^F^L^E^C^S TRANSLATOR. .S .TEST PAGE 8 ##^^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\\ .S .F ^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 (WITH THE EXCEPTION FOR INDENTED SOURCE FILES DETAILED BELOW). ^THERE IS SELDOM ANY NEED TO REFER TO THE STRAIGHT LISTING OF THE UNINDENTED SOURCE. .S ^COMMENT LINES ARE TREATED IN THE FOLLOWING WAY ON THE LISTING TO .x COMMENT LINES PREVENT INTERRUPTION OF THE DOTTED LINES INDICATING SCOPE: ^A COMMENT LINE THAT CONTAINS ONLY BLANKS (OR A TAB IN THE ^D^E^CSYSTEM-10 OR ^R^T-11 VERSIONS) IN COLUMNS 2 THROUGH 6 .x ^D^E^C ^R^T-11 .x ^D^E^Csystem-10 .x Tabs WILL BE LISTED WITH COLUMNS 7 THROUGH 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 THROUGH 6 OF A COMMENT CARD, THE CARD WILL BE LISTED WITHOUT INDENTATION. ^BLANK LINES MAY BE INSERTED IN THE SOURCE AND WILL BE TREATED AS EMPTY COMMENTS. .uc .s 1 In current DECsystem-10 and RT-11 versions of FLECS, "intra-line" .x ^D^E^C ^R^T-11 .x ^D^E^Csystem-10 .x intra-line comments .x comments, intra-line comments may also appear. The text of these comments should be placed to the right of each FLECS statement and preceeded by an exclamation point ("!"), following the conventions for FORTRAN .x exclamation points statements accepted by the compilers for those machines: .x ^^FORTRAN\\-10 .s 1 .nf .tp 5 keyword (specification) scope !comment .s 1 keyword (specification) !comment . scope !comment ...FIN !comment .s 1 .f .hl 1 ^INDENTED ^SOURCE ^FILES It has been suggested in the preceeding paragraphs that the user not try to indent the original source file and instead let FLECS do the proper indention automatically in the listing file. On a batch-oriented system this works well since the programmer will usually have such a source listing available during editing and debugging. But on timesharing systems, where the programmers view of the listing is restricted by the limitations of terminals (especially true for CRT terminals), indenting the SOURCE file itself would prove valuable in the input and editing of FLECS programs. Similarly, it is pedagogically unreasonable to tell a novice FLECS programmer that the listing is indented to make the program more understandable, just don't put any indention into your source! In programming courses where FLECS was the language vehicle, frequently students were found to "forget" and include the indention in the source file. .s 1 For these reasons, several FLECS implementations have been extended to allow for the input of indented source files. In particular, the .x indented source file DECsystem-10 and RT-11 FLECS translators will accept indented FLECS .x ^D^E^Csystem-10 .x ^D^E^C ^R^T-11 source files as input. On these systems, tab characters (_^I) may .x tabs be used to indent program statements as desired, provided that such tabs are the first characters in the text field of the statement. Here "text field" may be understood to mean either 1)#columns 7 through 72 or 2)#from after a tab occuring between columns 1 through 6 up to the end of the line. Any such "leading tab" character will be completely ignored by FLECS and the remainder of the statement will be processed and listed as usual according to its syntax. Thus, the FLECS programmer may use indentation to aid in the comprehension of the file being edited, but FLECS will not be confused in the event that the indention is wrong since it will be stripped away entirely before translation begins. Following is the indented source corresponding to the program above: .s 1 .tp 8 .nf 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 .f .s 1 But the maintenance of an indented source file itself becomes a problem: suppose the programmer makes a mistake in the FLECS syntax or in the indention itself. In order to maintain a current source file, it will be necessary to constantly update the source file with the correct indention. This problem is dramatically compounded when the programmer chooses to add, delete, or change any control structures whose scope include a large number of other statements. .s 1 To aid the FLECS programmer in this dilemma, these FLECS translators also provide the means of producing a new indented source file with the proper tabbing for the control structures present. (See the subsequent chapters on using the DECsystem-10 and PDP-11 translators for the command syntax to do this.) With the exception of indention, the new file will be identical in content to the original. So the FLECS user may re-create a new, up to date source file at any point: either each time the file is edited, or only when needed. .s 2 .lm 8 .rm 52 Note: The DECsystem-10 and RT-11 FLECS translators strip away all leading tabs in the statement text field of each line. To preserve such tab characters it is only necessary to insert a space in front of the first tab. It will no longer be a leading tab and thus will be preserved through the translation process. .lm 0 .rm 60 .lc .ch CONTROL STRUCTURES .LC .LM 0 .RM 60 ^A COMPLETE DESCRIPTION OF EACH OF THE EXTENDED CONTROL STRUCTURES .x CONTROL STRUCTURES PROVIDED BY ^F^L^E^C^S IS GIVEN BELOW TOGETHER WITH ITS GENERAL SYNTAX (FLOWCHARTS FOR ALL STRUCTURES APPEAR IN ^APPENDIX ^B). ^THE SYMBOL [^L] IS USED TO INDICATE A LOGICAL EXPRESSION. .x 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. .S ^A CONVENIENT SUMMARY OF THE INFORMATION IN THIS CHAPTER MAY BE FOUND IN ^APPENDICES ^A THROUGH ^C. .BR .hl 1 ^ALTERNATIVE ^STRUCTURES ^ALTERNATIVE (OR ^DECISION) STRUCTURES ARE STRUCTURED STATEMENTS .x ALTERNATIVE STRUCTURES .x DECISION STRUCTURES THAT CONTROL THE EXECUTION OF ONE OR MORE ALTERNATIVE SCOPES ON THE BASIS OF A LOGICAL EXPRESSION OR TEST. .BR .hl 2 ^THE ^^IF\\ ^STATEMENT .x ^^IF\\ statement ^DESCRIPTION: ^THE ^^IF\\ STATEMENT CAUSES A LOGICAL EXPRESSION TO BE EVALUATED. ^IF THE VALUE IS TRUE, THE SCOPE IS EXECUTED ONCE AND CONTROL PASSES TO THE NEXT STATEMENT. ^IF THE VALUE IS FALSE, CONTROL PASSES DIRECTLY TO THE NEXT STATEMENT WITHOUT EXECUTION OF THE SCOPE. .S ^GENERAL ^FORM: .S .NF ^^IF ( [L] ) $\\ .S .TP 3 ^EXAMPLES: .S ^^IF (X.EQ.Y) U = V+W\\ .S .TP 4 ^^IF (T.GT.0.AND.S.LT.R) . I = I+1 . Z = 0.1 ...FIN\\ .S 1 .F .hl 2 ^THE ^^UNLESS\\ ^STATEMENT .x ^^UNLESS\\ statement ^DESCRIPTION: "^^UNLESS ( [L] )"\\ IS FUNCTIONALLY EQUIVALENT TO "^^IF (.NOT.( [L] ))"\\ BUT IS MORE CONVENIENT IN SOME CONTEXTS. .S ^GENERAL ^FORM: .S .NF ^^UNLESS ( [L] ) $ .S 1 .TP 3 E\\XAMPLES: .S ^^UNLESS (X.NE.Y) U = V+W .S .TP 4 UNLESS (T.LE.0.OR.S.GE.R) . I = I+1 . Z = 0.1 ...FIN\\ .S 1 .F .hl 2 ^THE ^^WHEN...ELSE\\ ^STATEMENT .x ^^WHEN...ELSE\\ statement ^DESCRIPTION: ^THE ^^WHEN...ELSE\\ STATEMENTS CORRESPOND TO THE ^^IF...THEN...ELSE\\ STATEMENT OF ^ALGOL, ^P^L/^I, ^PASCAL, ETC. .X ^I^F...^T^H^E^N...^E^L^S^E STATEMENT .x ^ALGOL (LANGUAGE) .x ^P^L/^I (LANGUAGE) .x ^P^A^S^C^A^L (LANGUAGE) ^IN ^F^L^E^C^S, 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 ^^ELSE\\ STATEMENT. .S .NF .TP 4 ^GENERAL ^FORM: .S ^^WHEN ( [L] ) $1 ELSE $2\\ .S .TP 4 ^EXAMPLES: .S ^^WHEN (X.EQ.Y) U = V+W ELSE U = V-W\\ .S .TP 5 ^^WHEN (X.EQ.Y) . U = V+W . T = T+1.5 ...FIN ELSE U = V-W\\ .S .TP 5 ^^WHEN (X.EQ.Y) U = V+W ELSE . U = V-W . T = T+1.5 ...FIN\\ .S .TP 8 ^^WHEN (X.EQ.Y) . U = V+W . T = T-1.5 ...FIN ELSE . U = V-W . T = T+1.5 ...FIN\\ .S 2 .LM 8 .RM 52 .F ^NOTE: ^^WHEN\\ AND ^^ELSE\\ ALWAYS COME AS A PAIR OF STATEMENTS, NEVER SEPARATELY. ^EITHER THE ^^WHEN\\ OR THE ^^ELSE\\ OR BOTH MAY ASSUME THE MULTI-LINE FORM. ^^ELSE\\ IS CONSIDERED TO BE A CONTROL PHRASE, HENCE IT CANNOT BE PLACED ON THE SAME LINE AS ^^WHEN\\. ^THUS "^^WHEN#(#[L])#$1#ELSE#$2"\\ IS ^&NOT\& VALID. .s 2 .uc Note:##In the DECsystem-10 and RT-11 versions, the following syntax for the WHEN...ELSE statement is also accepted: .x ^D^E^Csystem-10 .x ^D^E^C ^R^T-11 .x ^^IF...THEN...ELSE\\ statement .s .nf IF ( [L] ) THEN $1 ELSE $2 .s .f The semantics for this statement is exactly the same as for the WHEN...ELSE statement: statement(s) $1 are executed if the condition [L] is true; alternatively statement(s) $2 are executed if the condition [L] is false. The keyword THEN must appear immediately after the condition and on the same line, even if $1 is a group of several statements on the following lines. Throughout the remainder of this manual, use of the term "WHEN...ELSE statement" may be understood to include the additional equivalent IF...THEN...ELSE syntax. .lc .LM 0 .RM 60 .hl 2 ^THE ^^CONDITIONAL\\ ^STATEMENT .x ^^CONDITIONAL\\ statement ^DESCRIPTION: ^THE ^^CONDITIONAL\\ STATEMENT IS BASED ON THE ^^LISP\\ .x ^^LISP\\ (LANGUAGE) 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 ^^CONDITIONAL\\. ^IF ALL EXPRESSIONS ARE FALSE, NO SCOPE IS EXECUTED. (^SEE, HOWEVER, THE NOTE ABOUT ^^OTHERWISE\\ BELOW.) .S ^GENERAL ^FORM: .S .TEST PAGE 8 .NF ^^CONDITIONAL . ( [L1] ) $1 . ( [L2] ) $2 . . . . . . . ( [L\N] ) $\N ...FIN\\ .S ^EXAMPLES: .S .TEST PAGE 5 ^^CONDITIONAL . (X.LT.-5.0) U = U+W . (X.LE. 1.0) U = U+W+Z . (X.LE.10.5) U = U-Z ...FIN\\ .S .TEST PAGE 9 ^^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\\ .F .S 2 .LM 8 .RM 52 ^NOTE: ^THE ^^CONDITIONAL\\ ITSELF DOES NOT HAVE A ONE-LINE FORM. ^HOWEVER, EACH "^^(#[L\I]#)#$\I"\\ IS TREATED AS A STRUCTURED STATEMENT AND MAY BE IN ONE-LINE OR MULTI-LINE FORM. .S 2 ^NOTE: ^THE RESERVED WORD ^^OTHERWISE\\ REPRESENTS A CATCHALL CONDITION. .x ^^OTHERWISE\\ statement ^THAT IS, "(^^OTHERWISE)#$\\I" IS EQUIVALENT TO "^^(.TRUE.)#$\\I" IN A ^^CONDITIONAL\\ STATEMENT. .LM 0 .RM 60 .hl 2 ^THE ^^SELECT\\ ^STATEMENT .x ^^SELECT\\ statement ^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, ^^[E1], [E2],..., [E3]\\ REPRESENT ARBITRARY BUT COMPATIBLE EXPRESSIONS. ^ANY TYPE OF EXPRESSION (INTEGER, REAL, COMPLEX, ...) IS ALLOWED AS LONG AS THE UNDERLYING ^F^O^R^T^R^A^N SYSTEM ALLOWS SUCH EXPRESSIONS TO BE COMPARED WITH AN ^^.EQ.\\ OR ^^.NE.\\ OPERATOR. .S ^GENERAL ^FORM: .S .TEST PAGE 8 .NF ^^SELECT ( [E] ) . ( [E1] ) $1 . ( [E2] ) $2 . . . . . . . ( [E\N] ) $\N ...FIN\\ .S ^EXAMPLES: .S .TEST PAGE 9 ^^SELECT (OPCODE(PC)) . (JUMP) PC = AD . (ADD) . . A = A+B . . PC = PC+1 . ...FIN . (SKIP) PC = PC+2 . (STOP) CALL STOPCD ...FIN\\ .S 2 .LM 8 .RM 52 .F ^NOTE: ^AS IN THE CASE OF ^^CONDITIONAL\\, AT MOST ONE OF THE $I WILL BE EXECUTED. .S 2 ^NOTE: ^THE CATCHALL ^^OTHERWISE\\ MAY ALSO BE USED IN A ^^SELECT\\ .x ^^OTHERWISE\\ statement STATEMENT. ^THUS "(^^OTHERWISE)#$\\N" IS EQUIVALENT TO "^^([E])#$\\N" WITHIN A "^^SELECT#([E]\\)" STATEMENT. .S 2 ^NOTE: ^THE EXPRESSION [^E] 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. .LM 0 .RM 60 .hl 1 ^REPETITIVE ^STRUCTURES .x repetitive structures .x loop structures ^THE STRUCTURED STATEMENTS DESCRIBED BELOW ALL HAVE A SCOPE THAT IS REPEATED A VARIABLE NUMBER OF TIMES DEPENDING ON SPECIFIED CONDITIONS. .S ^OF THE MANY LOOPS PRESENTED, THE NOVICE ^^FLECS\\ USER WILL FIND THE ^^DO, WHILE,\\ AND ^^REPEAT#UNTIL\\ LOOPS MOST USEFUL. ^TO AVOID CONFUSION, THE ^^UNTIL\\, ^^REPEAT#WHILE\\, ^^LOOP\\, AND ^^REPEAT#LOOP\\ LOOPS MAY BE INITIALLY IGNORED UNTIL THE USER HAS GAINED SOME EXPERIENCE AT PROGRAMMING IN ^^FLECS\\. .hl 2 ^THE ^^DO\\ ^STATEMENT .x ^^DO\\ statement ^DESCRIPTION: ^THE ^F^L^E^C^S ^^DO\\ LOOP IS FUNCTIONALLY IDENTICAL TO THE ^F^O^R^T^R^A^N ^^DO\\ LOOP; THE ONLY DIFFERENCES ARE SYNTACTIC. ^IN THE ^F^L^E^C^S ^^DO\\ LOOP, THE STATEMENT NUMBER IS OMITTED FROM THE ^^DO\\ STATEMENT, THE ITERATION PARAMETERS ARE ENCLOSED IN PARENTHESES, AND THE SCOPE IS INDICATED BY EITHER THE ONE-LINE OR MULTI-LINE CONVENTION. ^SINCE THE SEMANTICS OF THE ^F^O^R^T^R^A^N ^^DO\\ STATEMENT VARY FROM ONE ^F^O^R^T^R^A^N COMPILER TO ANOTHER, A FLOWCHART CANNOT BE GIVEN. ^THE SYMBOL [^I] REPRESENTS ANY LEGAL ITERATION SPECIFICATION. .S .NF ^GENERAL ^FORM: ^EQUIVALENT ^F^O^R^T^R^A^N: .S .TEST PAGE 3 ^^DO ( [I] ) $ DO 30 [I] $ 30 CONTINUE\\ .S ^EXAMPLES: .S ^^DO (I=1,N) A(I) = 0.0 .S .TEST PAGE 4 DO (J=3,K,3) . B(J) = B(J-1)*B(J-2) . C(J) = SIN(B(J)) ...FIN\\ .F .hl 2 ^THE ^^WHILE\\ ^STATEMENT .x ^^WHILE\\ statement ^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. .S ^GENERAL ^FORM: .S .NF ^^WHILE ( [L] ) $ .S E\\XAMPLES: .S .TEST PAGE 6 ^^WHILE (X.LT.A(I)) I=I+1 .S WHILE (P.NE.0) . VAL(P) = VAL(P)+1 . P = LINK(P) ...FIN\\ .F .hl 2 ^THE ^^REPEAT WHILE\\ ^STATEMENT .x ^^REPEAT WHILE\\ statement ^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: "^^REPEAT#WHILE(#[L]#)\\" IS FUNCTIONALLY EQUIVALENT TO "^^REPEAT#UNTIL(.NOT.(#[L]#))".\\ .S ^GENERAL ^FORM: .S .NF ^^REPEAT WHILE (#[L]#) $\\ .S ^EXAMPLES: .S ^^REPEAT WHILE (N.EQ.M(I)) I = I+1 .S .TEST PAGE 6 REPEAT WHILE (LINK(Q).NE.0) . R = LINK(Q) . LINK(Q) = P . P = Q . Q = R ...FIN\\ .F .hl 2 ^THE ^^UNTIL\\ ^STATEMENT .x ^^UNTIL\\ statement ^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: "^^UNTIL#(#[L]#\\)" IS FUNCTIONALLY EQUIVALENT TO "^^WHILE#(.NOT.(#[L]#))\\". .S ^GENERAL ^FORM: .S .NF ^^UNTIL ( [L] ) $\\ .S .TP 3 ^EXAMPLES: .S ^^UNTIL (X.EQ.A(I)) I = I+1 .S .TEST PAGE 4 UNTIL (P.EQ.0) . VAL(P) = VAL(P)+1 . P = LINK(P) ...FIN\\ .F .hl 2 ^THE ^^REPEAT UNTIL\\ ^STATEMENT .x ^^REPEAT WHILE\\ statement ^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. .S ^GENERAL ^FORM: .S .NF ^^REPEAT UNTIL ( [L] ) $\\ .S ^EXAMPLES: .S ^^REPEAT UNTIL (N.EQ.M(I)) I = I+1 .S .TEST PAGE 6 REPEAT UNTIL (LINK(Q).EQ.0) . R = LINK(Q) . LINK(Q) = P . P = Q . Q = R ...FIN\\ .F .UC .hl 2 The LOOP Statement The LOOP statement is the most general FLECS control .x ^L^O^O^P statement structure for iterative execution. This statement has two formats--its "general loop" form is describe here, while its "infinite loop" form is discussed separately below. .s 1 When used in the "general loop" form, the LOOP .x ^L^O^O^P statement>"general" form .x general ^L^O^O^P statement provides a means of specifying the four essential components of any "well-formed" loop: 1)#initialization, 2)#test, 3)#increment, .x initialization, loop .x loop>initialization .x test, loop .x loop>test .x increment, loop .x loop>increment .x body, loop .x loop>body and 4)#body. In order to allow for these components to be given, the syntax of the LOOP statement's specification clause differs from that of most FLECS statements. Where a logical expression for the test would normally be given enclosed by parentheses, the LOOP statement has the loop initialization, test, and increment steps, all within the parentheses and separated by semicolons. The test component is, as .x parentheses .x semicolons usual, a logical expression. But the initialization and increment portions, on the other hand, may be either of: 1)#a single FORTRAN statement (such as I#=#0 or I#=#I#+#1) or 2)#a FLECS internal procedure reference (such as INITIALIZE-TO-HEAD-OF-LIST or GET-NEXT-LINK). Thus, use of the LOOP statement in this form provides the unique ability (aside from the DO statement) to indicate in one statement all the essential information about the control of execution of the loop, and closely models similar control structures from other structured languages such as RATFOR and C. .x ^R^A^T^F^O^R .x ^C (language) .s Execution of the loop statement proceeds as follows: The initialization step is performed, either by the execution of the statement specified or by invocation of the indicated internal procedure. Then, the logical expression is tested, and, if the result is .TRUE., then the loop body (which may be in single- or multi-line forms, as usual) is performed. (Note that the scope of the statement may not be performed at all if the test is initially .FALSE.; in this respect, the LOOP statement is like the WHILE loop.) After each successful execution of the LOOP body, the increment statement or procedure is performed and control is then returned to the beginning of the loop for the next test. .s 1 .nf .tp 7 General Form: .s 1 LOOP ( #;#[L]#;# ) $ .s 1 ...where and may be... 1) a single FORTRAN statement 2) a FLECS internal procedure reference .s 1 .tp 5 Examples: .s 1 LOOP ( I=1#;#I.LE.N#;#I=I+1) . TYPE *,I ...FIN .s 1 .tp 4 N = 0 LOOP ( LNK=HEAD#;#LNK.NE.NULL#;#LNK=NODLNK(LNK) ) . N = N + 1 ...FIN .s 1 .tp 20 LOOP ( INIT-X#;#X.GE.XMIN#;#DECR-X ) ADD-TO-SUM ~ ~ ~ TO INIT-X . IF (X.EQ.0) . . TYPE 1 1 . . FORMAT (' Enter X: ',$) . . ACCEPT 2,X 2 . . FORMAT (I) . ...FIN ...FIN TO DECR-X . CONDITIONAL . . (X.GT.10.0) X = X - 1.0 . . (X.GT.100.0) X = X - 10.0 . . (OTHERWISE) X = X - 100.0 . ...FIN ...FIN TO ADD-TO-SUM . UNLESS (FUNCT(X).EQ.-1) CALL SUM (X) ...FIN .s 1 .f Any or all of the components specified in the control phrase may be omitted, so long as the two semicolon separators remain. The initialization and increment components default to "do nothing", while the test component defaults to "always succeed". So, the following two statements are both valid and equivalent: .s 1 .nf .tp 3 LOOP (#;#;#) $ .s 1 LOOP ( CONTINUE#;#.TRUE.#;#CONTINUE ) $ .s 1 .f .hl 2 The REPEAT LOOP statement As with the WHILE and UNTIL loops discussed above, there is a form of the LOOP statement which performs the test at the end of each iteration, rather than at the beginning. And, as before, this form is indicated by the word "REPEAT" in the syntax. The general form .x ^R^E^P^E^A^T ^L^O^O^P statement .x ^R^E^P^E^A^T ^L^O^O^P statement>"general" form .x general ^R^E^P^E^A^T ^L^O^O^P of the REPEAT#LOOP statement, like the LOOP statement, allows the specification of initialization, test, and increment clauses .x initialization, loop .x loop>initialization .x test, loop .x loop>test .x increment, loop .x loop>increment separated by commas in the control phrase. Execution of the REPEAT#LOOP statement is identical to that of the LOOP statement except that the test is done ^&after\& the body of the loop is executed. .x body, loop .x loop>body .s 1 .nf REPEAT LOOP ( #;#[L]#;# ) $ .s 1 ...where and may be... 1) a single FORTRAN statement 2) a FLECS internal procedure reference .s 1 .tp 4 Examples: .s 1 REPEAT LOOP ( N=1#;#K.GT.0#;#N=N+1 ) READ (1) K .s 1 .tp 6 F0 = FUNC(1.0) REPEAT LOOP ( X=0.1#;#DIF.LT.1.0E-5#;#X=X/10.0 ) . F1 = FUNC(X) . DIF = ABS(F1-F2) . F0 = F1 ...FIN .s 1 .f .hl 2 "Infinite" LOOPs The second form of the LOOP and REPEAT#LOOP statements is simply the degenerate form of the first form: the entire specification portion of the statement may be omitted, in which case the loop is assumed to be infinite. .x ^L^O^O^P statement>"infinite" form .x infinite ^L^O^O^P .x ^R^E^P^E^A^T ^L^O^O^P statement>"infinite" form .x infinite ^R^E^P^E^A^T ^L^O^O^P Obviously, infinite loops must be used with some degree of caution(!!!), but there are numerous occasions where the exact number of iterations for a loop cannot be calculated in any deterministic way. Examples might be "loop through all input lines in a file" or "process one command from the terminal" or "continue an iterative calculation until the result is 'good enough'". In such instances, an "infinite" loop may be the most straightforward control structure to use. (The BREAK statement, described later in this chapter, may be used to allow an exit route from such infinite loops--see the second example below.) .s 1 .nf .tp 3 General Form: .s 1 [ REPEAT ] LOOP $ .s 1 .tp 3 Examples: .s 1 REPEAT LOOP PROCESS-USER-COMMAND-UNTIL-EXIT .s 1 .tp 12 LOOP !Standard input loop follows... . READ (5,12,END=99) A,B,C 12 . FORMAT (3F10.2) . WHEN (.TRUE.) CONTINUE 99 v--ELSE BREAK . UNLESS (A.EQ.0. .OR. B.EQ.0. .OR. C.EQ.0.) . . X = A/B + B/C + C/A _^--.--IF (X.LT.0.0) NEXT . . WRITE (6,13) A,B,C,X 13 . . FORMAT (4F12.2) . ...FIN ...FIN .s 2 .f .lm 8 .rm 52 Note: The second form for the LOOP and REPEAT#LOOP statements may be considered to be the special case of the first format with all of the specification clause defaulted, that is, .s 1 .nf LOOP ( CONTINUE#;#.TRUE.#;#CONTINUE ) $ .s 2 .f Note: In the event its specification phrase is found to be in error, an invalid LOOP or REPEAT#LOOP statement will be repaired with a dummy specification which assures that the loop body will never be executed, as in the following example: .s 1 .nf LOOP ( CONTINUE#;#.FALSE.#;#CONTINUE ) $ .s 1 .f .s 1 Note: At present, the two LOOP statements have only been implemented in the DECsystem-10 and RT-11 versions of FLECS. .x ^D^E^Csystem-10 .x ^D^E^C ^R^T-11 .s 1 .lm 0 .rm 60 .hl 1 BRANCH STATEMENTS .x branch statements FLECS allows the use of two forms of "structured" branch statements as described below. These statements may only appear within the body of one of the FLECS loops described above, but ^¬\& within standard FORTRAN (non-FLECS) DO loops! .hl 2 The NEXT Statement Description: In its simplest form, execution of the NEXT statement .x ^^NEXT\\ statement causes the remainder of the current iteration of a loop to be skipped. Execution then continues at the control statement for the loop, either exiting or not, as conditions dictate. The NEXT statement may also appear with an optional number (the default is 1) which specifies the nesting level of the loop for which the "next" iteration is to be forced. Specifying 1 indicates that the immediately enclosing loop is to begin its next iteration. Specifying 2 indicates that the inner loop is to be exited completely and execution is to resume with the next iteration of the next outer loop. Specifying 3 indicates that 2 levels are to be exited and the next outer loop is to begin its next iteration, and so on. In the listing file, FLECS will indicate the loop associated with each NEXT by a row of dashes and a pointer to the loop control statement in addition to the usual indentation. .nf .s 1 .tp 3 General Form: .s 1 NEXT [ [_#] ] ...where [_#] is the nesting level .s 1 .tp 16 Example: .s 1 DO (I = 1, 10) _^--IF (D(I).EQ.0.0) NEXT . X(I) = N(I)/D(I) . IF (I.NE.1) . . DO (J = 1, I-1) . . . IF (X(I).EQ.X(J)) . . . . X(I) = 0.0 _^--.--.--.--NEXT 2 . . . ...FIN . . ...FIN . ...FIN . TYPE 1,I,X(I) 1 . FORMAT (1X,I2,1X,F6.2) ...FIN .s 1 .f In this example, each time D(I) is found to be zero, the outer loop is forced to its next iteration without executing the TYPE statement. If, in the inner loop, X(I) is the same as X(J), then the inner loop is exited and execution again continues with I getting its next value in the outermost DO loop. .s 2 .lm 8 .rm 52 Note: Execution of a NEXT statement which forces the next iteration of a LOOP or REPEAT#LOOP structure will cause a branch to the statement(s) generated for the increment clause specified for that structure, ^&after which\& control is passed to the loop exit test. .lm 0 .rm 60 .hl 2 The BREAK Statement Description: The BREAK statement is quite similar in format and use to .x ^^BREAK\\ statement the NEXT statement. It differs in that the specified loop is not forced to its next iteration; instead, the loop is immediately exited. Execution always continues, in this case, with the statement immediately following the end of the loop specified. As with the NEXT statement, if the loop level is not specified, it is assumed to be 1 and the immediately enclosing loop is exited. And, as in the case of the NEXT statement, the listing file will show the loop associated with each BREAK statement by a row of dashes and a pointer to the end of the loop in place of the usual indentation conventions. .nf .s 1 .tp 3 General Form: .s 1 BREAK [ [_#] ] ...where [_#] is the nesting level .s 1 .tp 13 Example: .s 1 TOTAL = 0.0 N = 0 LOOP !...thru all input grades . READ (20,5,END=9) GRADE 5 . FORMAT (F5.2) . WHEN (.TRUE.) CONTINUE 9 v--ELSE BREAK . TOTAL = TOTAL + GRADE . N = N + 1 ...FIN AVG = TOTAL / N .s 1 .f Here, the infinite-looking LOOP statement is executed until the data from FORTRAN logical unit number 20 is exhausted. At that time the BREAK statement at statement label 9 is executed, forcing immediate termination of the enclosing LOOP statement. Execution then resumes with the calculation of AVG from TOTAL and N. .s 2 .f .lm 8 .rm 52 Note: At present, the two BRANCH statements, NEXT and BREAK, have only been implemented in the DECsystem-10 and RT-11 versions of FLECS. .x ^D^E^Csystem-10 .x ^D^E^C ^R^T-11 .s 1 .lm 0 .rm 60 .LC .hl 1 ^INTERNAL ^PROCEDURES .x INTERNAL PROCEDURES ^IN ^F^L^E^C^S 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. .S ^&^PROCEDURE NAMES\& MAY BE ANY STRING OF LETTERS, DIGITS, AND .x PROCEDURE NAME .x ^^TO\\ PROCEDURE-NAME STATEMENT 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 IS MAY NOT BE CONTINUED ONTO A SECOND LINE. .S ^EXAMPLES OF VALID INTERNAL PROCEDURE NAMES: .S .NF .TEST PAGE 4 ^^INITIALIZE-ARRAYS GIVE-WARNING SORT-INTO-DESCENDING-ORDER INITIATE-PHASE-3\\ .S .F .hl 2 ^THE ^^TO\\ ^STATEMENT ^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 "^T^O" AND PROCEDURE NAME. ^OTHERWISE, THE STATEMENTS OF THE SCOPE ARE PLACED ON THE FOLLOWING LINES AND TERMINATED WITH A ^^FIN\\ STATEMENT. ^THESE RULES ARE ANALOGOUS WITH THE RULES FOR FORMING THE SCOPE OF A STRUCTURED STATEMENT. .S .NF .TP 3 ^GENERAL FORM OF PROCEDURE DECLARATIONS: .S ^^TO\\ PROCEDURE-NAME $ .S .TP 3 ^EXAMPLES OF PROCEDURE DECLARATIONS: .S ^^TO RESET-POINTER P = 0 .S TO DO-NOTHING CONTINUE .S .TEST PAGE 10 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\\ .F .hl 2 ^INTERNAL ^PROCEDURE ^REFERENCES ^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 ^F^L^E^C^S 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. .S ^A TYPICAL ^F^L^E^C^S PROGRAM OR SUBPROGRAM CONSISTS OF A SERIES OF ^F^O^R^T^R^A^N DECLARATIONS (^^INTEGER, DIMENSION, COMMON\\, ETC.) FOLLOWED BY A SERIES OF EXECUTABLE STATEMENTS (THE BODY OF THE PROGRAM), FOLLOWED BY ANY ^F^L^E^C^S INTERNAL PROCEDURE DECLARATIONS, FOLLOWED BY THE ^^END\\ STATEMENT. .PG ^HERE IS A COMPLETE (BUT UNINTERESTING) ^F^L^E^C^S PROGRAM THAT ILLUSTRATES THE PLACEMENT OF THE PROCEDURE DECLARATIONS. .NF .S 3 ---------------------------------------- .S 1 00010 ^^C PROGRAM FOR DEC\\SYSTEM^^-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 .S ---------------------------------------- .S 00130 TO GET-A-VALUE-OF-X 00140 . TYPE 10 00150 10 . FORMAT (' X = ',$) 00160 . ACCEPT 20,X 00170 20 . FORMAT(F) 00180 ...FIN .S ---------------------------------------- .S 00190 TO COMPUTE-RESULT XSQ = X*X .S ---------------------------------------- .S 00200 TO TYPE-RESULT 00210 . TYPE 30, XSQ 00220 30 . FORMAT(' X-SQUARED = ',F7.2) 00230 ...FIN .S ---------------------------------------- .S 00240 END\\ .PAGE .F ^NOTES CONCERNING INTERNAL PROCEDURES: .LS .RM 52 .LE ^ALL INTERNAL PROCEDURE DECLARATIONS MUST BE PLACED AT THE END OF THE PROGRAM JUST PRIOR TO THE ^^END\\ STATEMENT. ^THE APPEARANCE OF THE FIRST "^^TO\\" STATEMENT TERMINATES THE BODY OF THE PROGRAM. ^THE TRANSLATOR EXPECTS TO SEE NOTHING BUT PROCEDURE DECLARATIONS FROM THAT POINT ON. .LE ^THE ORDER OF THE DECLARATIONS IS NOT IMPORTANT. ^ALPHABETICAL BY NAME IS AN EXCELLENT ORDER FOR PROGRAMS WITH A LARGE NUMBER OF PROCEDURES. .LE ^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. .LE ^ANY PROCEDURE MAY CONTAIN REFERENCES TO ANY OTHER PROCEDURES (EXCLUDING ITSELF). .LE ^DYNAMIC RECURSION OF PROCEDURE REFERENCING IS NOT PERMITTED. .LE ^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. .LE ^THERE IS NO FORMAL MECHANISM FOR DEFINING OR PASSING PARAMETERS TO AN INTERNAL PROCEDURE. ^WHEN PARAMETER PASSING IS NEEDED, THE ^F^O^R^T^R^A^N 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. .LE ^THE ^F^L^E^C^S TRANSLATOR SEPARATES PROCEDURE DECLARATIONS ON THE LISTING BY DASHED LINES AS SHOWN IN THE PRECEDING EXAMPLE. .ELS .RM 60 .ch PREPROCESSOR FEATURES: DEC\s\y\s\t\e\m-10 _& RT-11 .uc .lm 0 .rm 60 In addition to its facilities for structured programming, the FLECS translator can provide several capabilities due to its role as a preprocessor of FORTRAN source code. In this chapter several of these features, as implemented on the DECsystem-10 and RT-11 versions of FLECS, are discussed. .x ^D^E^Csystem-10 .x ^D^E^C ^R^T-11 .hl 1 EXTENDED STATEMENTS In addition to the extensions to the control structures provided by FORTRAN, the FLECS preprocessor also provides a number of convenient additions to the language. These changes are implemented either by extensions to existing statements or by completely new statement types as described below. .hl 2 The RETURN Statement Description: the usual FORTRAN syntax for the RETURN statement has been extended in FLECS for the case of RETURNs from function .x ^^RETURN\\ statement .x subroutines .x function subprograms subprograms. The usual FORTRAN convention of using the function name as a variable as well is somewhat confusing to novice programmers and is replaced by a (hopefully) more elegant syntax. .nf .s 1 General Form: .s 1 RETURN ( [E] ) .s 1 .tp 6 Example: .s 1 REAL FUNCTION ABSVAL (X) WHEN (X.GE.0) RETURN (X) ELSE RETURN (-X) END .s 1 .f .s 1 .f FLECS will cause the appropriate statements to be generated to return the parenthesized expression as the value of the function. In the example above, either the value of X or the value of the expression -X is returned as the value of the function ABSVAL. .hl 2 The INCLUDE Statement Description: the INCLUDE statement specifies the name of a file .x ^^INCLUDE\\ statement to be included at this point in the input stream. FLECS will take its input from the specified file until it reaches the end of the included file, at which time input from the original file is resumed. Included files may contain any type of FORTRAN and FLECS statements, even other INCLUDE statements. (INCLUDEs may be nested to a maximum of 5 levels deep in current DECsystem-10 and RT-11 implementations.) .x ^D^E^Csystem-10 .x ^D^E^C ^R^T-11 .nf .s 1 General Form: .s 1 INCLUDE "file specification" .s 1 .f _...where the default extension for the file is .FLX in the versions of FLECS for the DECsystem-10 and RT-11 systems. .x ^D^E^Csystem-10 .x ^D^E^C ^R^T-11 .x extension>default .x default extension The text of the included file will appear in the listing file, if any, and the translated FORTRAN statements from the included input will be placed in the FORTRAN output file. .s 1 The FLECS INCLUDE statement is particularly useful for FORTRAN users of any system where the "native" FORTRAN compiler does not have an "include" feature. Even where the host FORTRAN supports this feature, there will still be the need to include source statements which must be translated by FLECS. .s Note that the syntax for the FLECS INCLUDE statement is very similar to that of FORTRAN-10's INCLUDE statement, differing only in the .x ^^FORTRAN\\-10 type of quotes used--FLECS uses double quotes (") around the file name while FORTRAN-10 uses single quotes ('). .x quotes>single .x quotes>double Use the FLECS INCLUDE statement when code is to be included which requires preprocessing by FLECS, that is, when FLECS control structures are used. When no translation is needed in the included file, the FORTRAN-10 form may be used (it is ignored by FLECS) to avoid the overhead of preprocessing source code which is entirely FORTRAN. .hl 2 The STRING Statement Description: the STRING statement may be used in FLECS programs to .x ^^STRING\\ statement facilitate the use of "FLECS-format" strings. This format uses an .x string>"^^FLECS\\"-format .x ^^FLECS\\-format strings integer array to store strings with the current length of the string in characters in the first word. The text of the string is packed in "An" format (where "n" is the number of characters per word on the host machine...4 for the IBM S/360, 5 for the DECsystem-10, 2 for the PDP-11, etc.) in .x ^D^E^Csystem-10 .x ^D^E^C ^R^T-11 .x ^^IBM S/360\\ the remainder of the array. In addition, in the RT-11 implementation, .x ^D^E^C ^R^T-11 one additional character space is allocated at the end of the string to allow room for the user to null terminate the string if the conventions of RT-11's SYSLIB library are to be followed. .x string library .x ^^SYSLIB\\ library ^^(RT-11)\\ .x library>^^SYSLIB (RT-11)\\ The STRING statement has two forms, one for the declaration of string variables and one for the initialization of string constants. .hl 3 String Variables .s 1 To set up a FLECS-format string to contain a given number of characters .x string>variable the first form of the STRING statement is used. .nf .s 1 .tp 3 General Form: .s 1 STRING variable (_#-chars) .s 1 .tp 4 Examples: .s 1 STRING LNAME(25) STRING CODE(3000), ALPHA(26), DIGITS(10) .s 1 .f The syntax is quite similar to that of the DIMENSION or INTEGER statements, and basically FLECS calculates the number of words in an integer array required to store the specified number of characters plus their length and dimensions the variable accordingly. .hl 3 String Constants .s 1 To create strings with constant or initial values, the second form .x string>constant of the STRING statement is used. .nf .s 1 .tp 3 General Form: .s 1 STRING variable 'text' .s 1 .tp 4 Examples: .s 1 STRING ALPHA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' STRING NULL '', DO 'DON''T' .s 1 .f This form uses the length of the text specified as the length of the string and will both dimension the integer array and initialize the string to the specified text. The text string is a standard FORTRAN literal and embedded single quotes (') may be represented as usual by two single quotes (''). .x quotes>single .s 1 STRING statements are limited, like other FLECS statements, to one line of code each thus limiting string constants to roughly 60 characters or so. In the event a longer string is desired, it will be necessary to use the form for string variables described above to create the array space and then to use the FORTRAN DATA statement to initialize the string manually (or split the string into 2 or more smaller strings). On the other hand, each STRING statement may consist of any number of either type of string declarations separated by commas as in the following example: .nf .s 1 STRING DIG'0123456789', LINE(80), WORD'AIN''T' .s 1 .f .s 1 Note that use of the STRING statement in FLECS programs will usually result in mixing INTEGER and DATA statements in the resulting FORTRAN code. While most modern FORTRAN compilers (including FORTRAN-10) can deal with such occurrences, most also insist on .x ^^FORTRAN\\-10 producing a warning message for each statement which appears out of order according to the "traditional" rules for statement ordering. To turn off this message from FORTRAN-10 (which inherited this archaic trait!) use the /NOWARN switch when compiling FLECS files .x switch>/^^NOWARN\\ .x ^^NOWARN\\ switch using the STRING statement as follows: .nf .s 1 .^&COMPIL_ file.FLX(NOWARN)\& .s 1 .f .s 1 The file FOR:STRLIB.REL contains a library of subroutines for use with .x string library .x ^^STRLIB\\ library (^D^E^Csystem-10) .x library>^^STRLIB\\ (^D^E^Csystem-10) "FLECS-format" strings, many of which were taken from the sources for .x string>"^^FLECS\\"-format .x ^^FLECS\\-format strings the FLECS translator itself. For a complete description of these routines, consult the file FOR:STRLIB.PLM. .hl 1 SYSTEM COMMANDS .x system commands .x commands>system .x $ commands .x commands>$ Description: Any line in a FLECS source file which contains a dollar sign ("$") in column one will be treated as a command to the preprocessing system itself. Such commands will (usually) not be included in either the listing file or the file of generated FORTRAN statements (they will, however, be output to indented source files). In general, these commands have the following syntax: .s 1 .nf General Form: $ [ ] .s 1 .f _...where may be reduced to its shortest unique abbreviation (except where noted), and are optional and may take several forms. Also, any number of spaces (and/or tabs--_^I's) may appear on .x tabs either side of the keyword for readability. .hl 2 Conditional Translation .x conditional translation .x translation>conditional .x conditional commands .x commands>conditional This class of system commands may be used to conditionally control translation of lines from the input file. Each must be followed by an which qualifies the command. The argument format is any string of alphanumeric characters, of which, only the first "n" of which are significant--where "n" is the number of "A1" format characters per word on the host machine. The arguments represent variables which are used as "logical flags" or "feature test switches" in determining whether each line in the source file is to be processed or ignored. The current implementation allows for up to 10 variables to be defined during each translation. .hl 3 The $TRUE _& $FALSE Commands .x $^T^R^U^E command .x $^F^A^L^S^E command .s 1 The $TRUE and $FALSE commands may be used to define a variable and set its initial value. At any subsequent point, these commands may also be used to change a variable's value, although this change will not take effect until the next $IF, $UNLESS, or $FIN command is encountered (see below). .s 1 .nf .tp 2 General Form: $TRUE variable $FALSE variable .s 1 .tp 5 Examples: .s 1 $TRUE DEC10 .s 1 $FALSE SINGLEPRECISION .s 1 .f .hl 3 The $IF Command .x $^I^F command .s 1 The $IF command will turn on processing of subsequent lines from the source file if the value of the specified variable is currently TRUE; if the variable is FALSE, then subsequent lines will be completely ignored, except for subsequent conditional translation commands of course! When translation is disabled in this manner, regular input lines are completely ignored and are suppressed from both the listing and FORTRAN output files but will appear in indented source output. $IF statements may be nested, and their scope is controlled by $FIN .x $^F^I^N command statements in exactly the same manner as in any regular FLECS multi-line statement. Note that $IF commands (and matching $FIN's) may not be abbreviated, just as regular FLECS statement keywords may not. .s 1 .nf General Form: $IF variable .s 1 .tp 9 Example: .s 1 $TRUE ANSI ~ ~ ~ $IF ANSI | | (source translated only if ANSI = .TRUE.) v $FIN .s 1 .f .hl 3 The $UNLESS Command .x $^U^N^L^E^S^S command .s 1 The $UNLESS system command bears exactly the same relationship to the $IF command as does the UNLESS statement to the IF statement. $UNLESS may be thought of as "$IF#NOT#variable", although this syntax itself is not supported. As with the $IF command, $UNLESS may not be abbreviated. .s 1 .nf General Form: $UNLESS variable .s 1 .tp 9 Example: .s 1 $TRUE ANSI ~ ~ ~ $UNLESS ANSI | | (source translated only if ANSI = .FALSE.) v $FIN .s 1 .f The conditional translation capabilities of FLECS allow for several .x conditional translation .x translation>conditional variants of the same source program to be maintained in one file, thus eliminating "skew" problems due to alterations to one version differing from others when in fact they should be applied globally. The following example illustrates the use of conditional translation commands to implement a floating point absolute value function in both REAL and DOUBLE#PRECISION forms. .s 1 .nf .tp 20 Example of a source file using conditional translation: .s 1 $TRUE DP (...or... $FALSE DP) C Absolute Value Function... $IF DP C ...Double Precision Version DOUBLE PRECISION FUNCTION ABSVAL (X) DOUBLE PRECISION X, TEMP, ZERO, MINUS1 DATA ZERO/0.0D0/, MINUS1/-1.0D0/ $ FIN $UNLESS DP C ...Single Precision Version REAL FUNCTION ABSVAL (X) REAL X, TEMP, ZERO, MINUS1 DATA ZERO/0.0E0/, MINUS1/-1.0E0/ $ FIN WHEN (X.GE.ZERO) TEMP = X ELSE TEMP = X * MINUS1 RETURN (TEMP) END .s 1 .f Note that the translated source statements will appear in the listing file while those which are ignored will be omitted; all system commands will be suppressed from the listing as well. All input lines which are not translated will, however, be output to indented source files; .x indented source file such lines will not be indented since the context for their indentation is unknown. .hl 2 Symbolic Substitution .x symbolic substitution .x substitution, symbolic Because FLECS must scan each line in the FLECS input file to determine when preprocessing is necessary, it can also be used to make symbolic substitutions in the source text. This feature may be used to parameterize computations and thereby reduce the chance of error due to incorrectly changing array sizes, etc. String substitution may also be used to define characters such as "_&" and "|" to represent the usual FORTRAN operators .AND. and .OR., providing a means for extensibility and a more readable listing file. This feature is currently available only on the DECsystem-10. .x ^D^E^Csystem-10 .hl 3 The $DEFINE Command .x $^D^E^F^I^N^E command .s 1 The $DEFINE system command is used to define the symbols to be removed from the input stream and the strings with which they are to replaced in the format shown here: .s 1 .nf General Form: $DEFINE [ ] .s 1 .f _...where is the input symbol and is its replacement string. may be either 1)#an arbitrary string of alphanumeric characters, or 2)#any other single non-blank character. is optional and may consist of any string of non-blank characters; if omitted, defaults to the null (empty) string. (As usual, "non-blank" is assumed to mean "non-tab" also.) Notice in the example below that $DEFINE commands, unlike most system commands, will be output to the listing file (the $[NO]LIST commands described later may be used to avoid this). .s 1 .nf .tp 14 Example of a source file using symbolic substitution: .s 1 $DEFINE { $DEFINE } FIN $DEFINE _& .AND. $DEFINE NCELLS 10 ~ ~ ~ DIMENSION CELL(NCHARS) ~ ~ ~ IF (ANS.EQ.'Y' _& K.EQ.1) { TYPE 12,CELL 12 FORMAT (1X,NCELLS(A1)) } ~ ~ ~ .s 2 .tp 14 Example listing file from the source listed above: .s 1 $DEFINE { $DEFINE } FIN $DEFINE _& .AND. $DEFINE NCELLS 10 ~ ~ ~ DIMENSION CELL(NCELLS) ~ ~ ~ IF (ANS.EQ.'Y' _& K.EQ.1) { . TYPE 12,CELL 12 . FORMAT (1X,NCELLS(A1)) ...} ~ ~ ~ .s 2 .tp 10 Example object file from the source listed above: .s 1 ~ ~ ~ DIMENSION CELL(10) ~ ~ ~ IF (.NOT.(ANS.EQ.'Y' .AND. K.EQ.1)) GO TO 99999 TYPE 12,CELL 12 FORMAT (1X,10(A1)) 99999 CONTINUE ~ ~ ~ .s 1 .f .hl 3 The Substitution Algorithm .s 1 FLECS uses the following algorithm to perform symbolic substitutions: At the begining of each routine (main program, subroutine, function, etc.) FLECS clears all previously defined symbols. Until a definition is encountered (i.e., a $DEFINE command), translation proceeds as usual. Once any definitions have been made, FLECS makes an extra pass over each non-comment, non-system-command input line before beginning the usual translation. During this extra pass, the line is scanned left to right, beginning in column 7 in the statement text field of the line. Any currently defined symbol found in this field will be replaced, and the scan continues from immediately after the replacement string. Symbols which will be considered for replacement are: 1)#any string of alphanumeric characters delimited by non-alphanumerics, or 2)#any other non-blank, non-alphanumeric character. For alphanumeric strings, substitution is performed without regard to case; that is, defined symbols and their substitutions are shifted to upper case automatically. Also, substitutions are performed without regard to the possible existence of quoted strings, Hollerith constants, or intra-line comments. Then, after all substitutions have .x Hollerith .x intra-line comments .x comments, intra-line been made, the resulting line is then checked for FLECS statements and processed or passed directly to the FORTRAN output file as usual. .lm 8 .rm 52 .s 1 Note: Because symbolic substitution requires FLECS to perform an additional pass over each input line, translation times will increase significantly whenever any symbol definitions are present. This increase is roughly 20% on the DECsystem-10. FLECS will make the .x ^D^E^Csystem-10 extra pass only after it has encountered the first $DEFINE command; therefore, definitions should be placed as far down in the source file as possible to reduce execution time. .lm 0 .rm 60 .hl 2 Listing Control .x listing control commands .x commands>listing control There are presently two commands for controlling the contents of the desired contents of the output listing file, as described in the following paragraphs. .hl 3 The $PAGE Command .x $^P^A^G^E command .s 1 The $PAGE command (or any abbreviation thereof) will generate a new page in the listing file at the point where it is encountered and subsequent lines output to the listing will be printed on the next page. The command itself will not be output to the listing, but will be included in indented source output files. .s 1 .nf General Form: $PAGE .s 1 .f .hl 3 The $[NO]LIST Command .x $^L^I^S^T command .x $^N^O^L^I^S^T command .s 1 The $NOLIST command may be used to suppress any and all subsequent output to the listing file. To restore listing, the $LIST command may be given. These commands will have no effect if no listing file is being output. As with the $PAGE command described above, $NOLIST and $LIST commands may be abbreviated and will not appear in any output files except for indented source files. .s 1 .nf .tp 2 General Form: $NOLIST $LIST .s 1 .f One useful application of the $NOLIST and $LIST commands is to suppress INCLUDEd files containing COMMON definitions from the source listing when they are lengthy and/or repeated. .s 2 .lm 8 .rm 52 Note: Errors encountered with the listing suppressed will not appear in the output file but will be typed out on the users terminal. But, if the output listing file is specified as "TTY:" then no errors will appear while $NOLIST is in effect. In any event, FLECS' summary of major and minor errors will always be displayed. .lm 0 .rm 60 .lc .ch ERRORS .LC .LM 0 .RM 60 ^THIS SECTION PROVIDES A FRAMEWORK FOR UNDERSTANDING THE ERROR-HANDLING .x ERRORS MECHANISMS OF ^VERSION 22 (AND LATER) OF THE ^F^L^E^C^S ^TRANSLATOR. ^THE SYSTEM DESCRIBED BELOW IS AT AN EARLY POINT IN EVOLUTION, BUT IT HAS PROVED TO BE QUITE WORKABLE. .S ^THE ^F^L^E^C^S TRANSLATOR EXAMINES A ^F^L^E^C^S 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. .hl 1 ^SYNTAX ^ERRORS .x SYNTAX ERRORS ^WHEN THE TRANSLATOR DETECTS A SYNTAX ERROR, ^&IT IGNORES THE STATEMENT\&. ^ON THE ^F^L^E^C^S LISTING THE LINE NUMBER OF THE STATEMENT IS OVERPRINTED WITH "-"'S TO INDICATE THAT THE STATEMENT HAS BEEN IGNORED. ^THE NATURE OF THE SYNTAX ERROR IS GIVEN IN A MESSAGE ON THE FOLLOWING LINE. .S ^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. .hl 1 ^CONTEXT ^ERRORS .x 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 ^^FIN\\S NEEDED AT SOME POINT IN THE PROGRAM. .S ^WITH THE EXCEPTION OF EXCESS ^^FIN\\S THAT DO NOT MATCH ANY PRECEDING CONTROL PHRASE AND ARE IGNORED (AS INDICATED BY OVERPRINTING THE LINE NUMBER), 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. .S ^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\&. .S ^ONE NICE FEATURE OF THE CONTEXT ADJUSTMENT STRATEGY IS THAT CONTEXT ERRORS CANNOT PROPAGATE PAST A RECOGNIZABLE PROCEDURE DECLARATION. ^THIS IS BECAUSE THE "^T^O" DECLARATION IS IN CONTEXT ONLY AT INDENTATION LEVEL 0. ^THUS, TO PLACE THE "^^TO\\" IN CONTEXT, THE TRANSLATOR MUST INVENT ENOUGH STATEMENTS TO TERMINATE ALL OPEN CONTROL STRUCTURES WHICH PRECEDE THE "^T^O." ^THE PROGRAMMER WHO MODULARIZES HIS PROGRAM INTO A COLLECTION OF RELATIVELY SHORT INTERNAL PROCEDURES LIMITS THE POTENTIAL FOR PROPAGATION OF CONTEXT ERRORS. .BR .hl 1 ^UNDETECTED ^ERRORS ^THE ^F^L^E^C^S TRANSLATOR IS IGNORANT OF MOST DETAILS OF .x UNDETECTED ERRORS ^F^O^R^T^R^A^N SYNTAX. ^THUS, MOST ^F^O^R^T^R^A^N SYNTAX ERRORS WILL BE DETECTED BY THE ^F^O^R^T^R^A^N COMPILER RATHER THAN BY THE ^F^L^E^C^S TRANSLATOR. ^IN ADDITION, THERE ARE TWO MAJOR CLASSES OF ^F^L^E^C^S ERRORS THAT WILL BE CAUGHT BY THE COMPILER AND NOT BY THE TRANSLATOR. .S ^THE FIRST CLASS OF UNDETECTED ERRORS INVOLVES MISSPELLED ^F^L^E^C^S KEYWORDS. .x KEYWORDS ^A MISSPELLED KEYWORD WILL NOT BE RECOGNIZED BY THE TRANSLATOR. ^IT WILL ASSUME THE LINE ON WHICH THE WORD OCCURS TO BE A ^F^O^R^T^R^A^N 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 ^L'S. ^SUCH STATEMENTS ARE PASSED TO THE COMPILER, WHICH THEN PRODUCES AN ERROR MESSAGE. ^THE FACT THAT AN INTENDED CONTROL PHRASE WAS NOT RECOGNIZED FREQUENTLY CAUSES A LATER CONTEXT ERROR, SINCE A LEVEL OF INDENTATION WILL NOT BE TRIGGERED. .S ^THE SECOND CLASS OF UNDETECTED ERRORS INVOLVES UNBALANCED PARENTHESES .x PARENTHESES (^SEE ALSO ^NOTE 8 IN CHAPTER 6). ^WHEN SCANNING A PARENTHESIZED SPECIFICATION, THE TRANSLATOR LOOKS FOR A LEFT PARENTHESIS TO MATCH THE INITIAL RIGHT PARENTHESIS THAT BEGINS THE SPECIFICATION. ^AS SOON AS IT FINDS ONE, IT ASSUMES THAT THE REMAINDER OF THE LINE IS A SIMPLE ^F^O^R^T^R^A^N STATEMENT, WHICH IT PASSES TO THE COMPILER. ^OF COURSE, THIS ASSUMPTION MAY BE WRONG. ^THUS THE STATEMENT .S .NF ^^WHEN (X.LT.A(I)+Z)) X = 0\\ .F .S IS BROKEN INTO .S .NF KEYWORD ^^"WHEN"\\ SPECIFICATION ^^"(X.LT.A(I)+Z)\\" ^F^O^R^T^R^A^N STATEMENT ^^") X = 0\\" .S .F ^NEEDLESS TO SAY, THE COMPILER WILL OBJECT TO "^^)#X#=#0\\" AS A STATEMENT. .S ^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. .S ^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. .BR .hl 1 ^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!) .ch OPERATING PROCEDURES: DEC\S\Y\S\T\E\M-10 .UC .LM 0 .RM 60 .hl 1 SOURCE PREPARATION .x ^D^E^Csystem-10 .x source preparation FLECS source files on the DECsystem-10 may be created with any file name and extension at all, but the standard default extension .x filename .x default extension .x extension>default is .FLX. The translator will accept either line-numbered files .x ^S^O^S>line sequence numbers .x line sequence numbers>^S^O^S (e.g., from SOS) or non-line-numbered files (e.g., from TECO). .x ^T^E^C^O The advantage of line numbered files is that the translator and compiler error messages may be related directly to the source file without reference to a listing. As with FORTRAN-10, the "tab to .x ^F^O^R^T^R^A^N-10 column 7" convention may be used. .hl 1 EXPLICIT INVOCATION On the DECsystem-10, FLECS may be executed in one of two ways: .x ^^DEC\\system-10 by explicitly running the translator or by evoking it through one of the various COMPILe-class commands. FLECS may be invoked explicitly by the command... .nf .s 1 .^&R_ FLECS\& .s 1 .f FLECS will begin execution by typing out its current version number and prompting for a command string with a star (*). The general format for commands to FLECS is as follows... .nf .s 1 *^&[file.FOR,file.LST,file.FIN=]file.FLX[/switches]\& .s 1 .f _...where everything except the name of the input file is optional. .s 1 This command format is roughly the same as that for the FORTRAN-10 compiler itself, with the file name on the right-hand side of .x ^^FORTRAN\\-10 .x command format the equal sign specifying the input file (in this case a FLECS file) and the first two files on the left-hand side specifying the FORTRAN output file (here a file of pure FORTRAN code) and the listing file. .x listing The third output file specification is for the FLECS indented source .x indented source file file (see the description of this file in Chapter 3). Any or all of these three file names may be omitted; in the event that none are specified, the input file is checked for syntax (errors are reported to the user's terminal) and nothing else is done. If the equal sign is omitted also, then both the FORTRAN and listing output files are automatically generated with the same filename as that of the input file. The defaults for extensions are .FOR, .LST, .FIN, and .FLX for the FORTRAN, listing, indented source, and FLECS files, .x filename .x extension>default .x default extension respectively. All file specifications may include optional device and path specifications (including SFD's). .s 1 The list of switches is optional; currently there are three valid switches (any others will simply be ignored); these switches are described below. .hl 2 The /INCLUDE Switch .x switch>/^^INCLUDE\\ .x ^^INCLUDE\\ switch The switch /INCLUDE serves the same function in FLECS as it does in FORTRAN-10, informing the translator that lines beginning with the character "D" in column 1 are to be treated as debugging lines and should be translated as .x debugging lines normal FLECS statements--without the /INCLUDE switch, such lines are completely ignored and appear in neither output file. .hl 2 The /STANDARD Switch .x switch>/^^STANDARD\\ .x ^^STANDARD\\ switch The /STANDARD switch may be used to request that the indented source file be formatted according to the rules of the FORTRAN language standard, namely, that the statement begins in column 7 and that the line number and continuation fields occupy the first 6 columns. If this option is negated by the inclusion of the prefix "NO", then the formatting convention used by most FORTRAN-10 programmers .x ^^FORTRAN-10\\ will be used: statement numbers (if any) will be left justified to column 1, followed by a tab character (_^I) and the statement text. .x tabs The default for this switch is /NOSTANDARD. .hl 2 The /NUMBER Switch .x switch>/^^NUMBER\\ .x ^^NUMBER\\ switch To output a new .FIN indented source file with SOS line sequence numbers, .x ^S^O^S>line sequence numbers .x line sequence numbers>^S^O^S the /NUMBER switch must be used. In the default case, i.e., /NONUMBER, no line numbers will be output, although page marks--form feed characters (_^L)--will be preserved. If the switch /NUMBER is given, .x page marks .x form feeds then FLECS will use the line numbers found on the original input source file if present; if the original file is unsequenced, FLECS will use the line numbers generated for the FORTRAN and listing files. .s 1 .lm 8 .rm 52 Note: The presence of either the /STANDARD switch or the /NUMBER switch in a FLECS command line implies the generation of an indented source output file, regardless of the specification of a .FIN file name in the command. If no such name appears, FLECS will use the usual defaults in creating one. .s 1 .lm 0 .rm 60 .hl 1 COMPILE-CLASS COMMANDS The usual DECsystem-10 COMPILe-class commands such as .COMPILE, .LOAD, .x ^^COMPIL\\e-class commands .x commands>^^COMPIL\\e-class _.EXECUTE, and .DEBUG will recognize files with .FLX extensions as FLECS source files and will take the necessary steps to first translate the FLECS statements to FORTRAN using the FLECS translator and then to pass the translated code to the FORTRAN compiler for translation into object code. In the event that a FLECS source file does not have the usual .FLX extension, to compile it will require use of the /FLECS switch to COMPIL as follows: .x switch>/^^FLECS\\ .x ^^FLECS\\ switch .nf .s 1 .^&EXEC_ file.ext/FLECS\& .s 1 .f The standard COMPILe-class switch /LIST may also be appended to request that FLECS produce a listing file; /CREF may also be used, but it will simply be taken as a synonym for /LIST. When the /LIST switch is used, only a FLECS listing is produced, and the FORTRAN listing file is suppressed. In order to produce the FORTRAN listing, it is necessary to run the FORTRAN compiler directly. .x switch>/^^LIST\\ .x ^^LIST\\ switch .x switch>/^^CREF\\ .x ^^CREF\\ switch .s 1 COMPIL will also allow the user to pass switches to the FLECS and .x switch>^^COMPIL\\e-class .x ^^COMPIL\\e-class switch FORTRAN compilers (all switches are passed to both--FLECS ignores any that it does not use). The format for passing switches in this case is to inclose the entire list--except for the initial slash--in parentheses after the file name as in the following example: .nf .s 1 .^&DEBUG_ file.ext(switch1/switch2.../switchN)/LIST\& .s 1 .f Note that the /STANDARD and /NUMBER switches must not be passed to the FORTRAN compiler: they may only be used if the .COMPIL command is used together with the standard COMPIL switch /NOBINARY. .x switch>/^N^O^B^I^N^A^R^Y The following example illustrates the creation of an indented source file and a listing file from a FLECS source file: .nf .s 1 .^&COMPIL_ file.ext(NONUMBER/NOSTANDARD)/LIST/NOBIN\& .s 1 .f The new indented source will have no line sequence numbers and will be formated according to usual FORTRAN-10 (non-standard) rules, and the FORTRAN compiler will not be run since no object (i.e., .FOR) file will have been created by FLECS. .lm 8 .rm 52 .s 2 Note: Uninvoked internal procedures and too many or too few "FIN"'s preceeding a TO or END statement are considered minor errors by FLECS. All others are considered major. If any major errors are detected by the translator, it will abort any following compilation, loading, and execution. .s 2 Note: COMPIL invokes the FLECS translator whenever the .FOR file is missing or older than the .FLX file, regardless of the existence or timestamp of a .REL file. If you wish to save disk space by deleting the .FOR file, you must then use the command ".EXEC#file.REL" to avoid retranslation and recompilation. .s 2 Note: If COMPIL finds an .FOR file which is newer than the .FLX file, it assumes (without looking) that the matching .REL file also exists. LINK, of course, will be unhappy if this is not true. To create a new .REL file without retranslation, use the command ".EXEC#file.FOR". .lm 0 .rm 60 .ch OPERATING PROCEDURES: PDP-11 \W\I\T\H RT-11 .UC .LM 0 .RM 60 .x ^D^E^C ^R^T-11 Under the RT-11 operating system FLECS must be invoked directly by running FLECS using the standard RT-11 command format: .nf .s 1 .R FLECS or .RUN [DEV:]FLECS .f .s 1 FLECS will begin execution by typing out its current version number and prompting for a command string with a star (*). At this point the user may either type a command in the following format (standard RT-11 format)... .nf .s 1 *O,L,I=S .s 1 Where: O = Fortran Output file spec L = Flecs Listing file spec I = Indented source file spec S = Flecs Source file spec .s 1 ...or type an abbreviated command of the form... .s 1 *S .f .s 1 ...in which case a generated FORTRAN file and a FLECS listing file are created with the same file name as the source on the same RT-11 device as the source. Note that all file specifications are in standard RT-11 format, and that in the first type of command each output file specification is optional. .tp 30 .hl 1 DEFAULT EXTENSIONS The following file extensions apply as defaults to any file .x extension>default .x default extension specification in which an extension is missing: .s 1 .nf ^&File\& ^&Extension\& .s 1 O - FORTRAN .FTX (&FOR&TRAN from FLE&X) L - listing .FLL (&F&LECS &listing) I - indented source .FIN (&FLECS &i&ndented source) S - FLECS SOURCE .FLX (&F&LE&X) .F .TP 30 .hl 1 SWITCHES The following switches are currently implemented under RT-11: .x switch>^^RT-11\\ .s 1 .lm 8 .rm 52 .i -4;/C##include &comment lines in generated FORTRAN file .i -4;/D##include lines with a 'D' in column 1 (&debugging lines) .i -4;/L##place the corresponding FLECS listing &line numbers in columns 75-80 of the generated FORTRAN file (see note below) .i -4;/N##produce a &new INDENTED source file .s 1 .lm 8 .rm 52 Note: The /L switch may be useful in debugging with FDT but its general use should be avoided as it produces a MUCH BIGGER file! .ch OPERATING PROCEDURES: IBM S/360 .uc .lm 0 .rm 60 .hl 1 FLECS VERSIONS FOR IBM SYSTEMS On the IBM S/360 there are two ways of accessing FLECS which have .x ^I^B^M ^S/360 come to be known as WATFLECS and Standard FLECS. WATFLECS is a .x ^W^A^T^F^L^E^C^S specially adapted version of the FLECS translator which processes batches of short jobs using the WATFIV compiler and is used .x ^W^A^T^F^I^V primarily in conjunction with Computer Science classes. Standard FLECS is a stand alone FLECS translator used for larger production programs, usually in conjunction with the level G FORTRAN compiler. Cataloged procedures which are analogous to those for FORTRAN(G) .x ^F^O^R^T^R^A^N(^G) .x cataloged procedures exist for using Standard FLECS. WATFLECS is accessed through a special submission process. The same FLECS translation logic is used for both systems, so the only language differences are those due to the incompatibilities of the corresponding FORTRANs. .hl 1 WATFLECS The procedure for preparing and submitting a program under WATFLECS is almost identical to the procedure for submitting a job under WATFIV. .x ^W^A^T^F^L^E^C^S .x ^W^A^T^F^I^V The deck set up is shown below: .s .nf .tp 12 $JOB ...WATFIV parameters . . FLECS source program . . $ENTRY . . data cards (if any) . . .s .f .tp 3 Notes on preparing a WATFLECS program: .ls .le;^&An 029 keypunch must be used\&. .le;WATFIV does not follow the ANSI standard for FORTRAN in that it does not allow a FORTRAN program to jump out of the scope of a DO loop and later jump back in. Since FLECS internal procedure calls are implemented by GO#TO's, ^&it is not possible to reference an internal procedure within the scope of a DO loop when using WATFLECS\&. Any of the other loop structures may be used to simulate a DO loop, however. .le;^&Terminate a WATFLECS main program by placing a STOP statement ahead of the first internal procedure declaration\&. .le;The following unit numbers are available in WATFLECS: .s .nf ^&Unit\& ^&Physical_ Device\& 1 card input (from $ENTRY cards) 2 undefined 3 printed output 4-7 scratch disk (READ/WRITE) 8-10 class input data sets (READ only) .s .f .le;The various "$" cards which control the listing of a WATFIV program may be included in the program but will be ignored by the WATFLECS system. .le;The user may wish to employ the NOWARN and NOEXTEN WATFIV parameters since FLECS-generated FORTRAN triggers many warnings and extensions. .els .hl 1 STANDARD FORTRAN A cataloged JCL procedure exist for using the FLECS translator as a stand-alone program. In addition, cataloged procedures exist for .x ^J^C^L .x cataloged procedures running FLECS followed by FORTRAN(G). .x ^F^O^R^T^R^A^N(^G) .hl 2 Data Sets for the Translator The translator requires three data sets with the following names: .s .lm 16 .rm 52 .i -8;SYSIN###is the input data set containing the FLECS source. .s .i -8;LIST####is the output data set containing the FLECS listing. .s .i -8;FORTOUT#is the output data set containing the FORTRAN source produced by the translator. .s .lm 0 .rm 60 The DCB information for these data sets is given below. It is fixed and contained in the program, hence it need not be specified in the JCL. .s .lm 16 .rm 52 .i -8;SYSIN###DCB=(RECFM=F,BLKSIZE=80) .s .i -8;LIST####DCB=(RECFM=FA,BLKSIZE=133) .s .i -8;FORTOUT#DCB=(RECFM=F,BLKSIZE=80) .s .lm 0 .rm 60 .hl 2 Using the Translator Stand-Alone The cataloged procedure FLECS is a one step procedure which runs the FLECS translator. The user must supply the SYSIN data set. Default DD statements in the procedure send LIST to the printer and FORTOUT to a dummy data set. If desired, these DD statements may be overridden as illustrated in the examples below: .s 1 Example: Obtaining a printed FLECS listing and ignoring the FORTRAN source produced. .s 1 .nf .tp 9 //jobname JOB accounting information //stepname EXEC FLECS //SYSIN DD * . . FLECS source program . . /* .s 1 .f Example: Obtaining a printed version of both the FLECS listing and the FORTRAN source files. .s 1 .nf .tp 10 //jobname JOB accounting information //stepname EXEC FLECS //FORTOUT DD SYSOUT=A //SYSIN DD * . . FLECS source program . . /* .s 1 .f Example: Obtaining a printed version of the FLECS listing and passing the FORTRAN source to the FORTRAN(H) compiler for compilation only. .x ^F^O^R^T^R^A^N(^H) (This example illustrates the general method of passing the FORTRAN source file to a subsequent job step and suppressing the FORTRAN listing.) .s 1 .nf .tp 13 //jobname JOB accounting information //stepname1 EXEC FLECS //FORTOUT DD DSNAME=_&TEMP,DISP=(NEW,PASS), // UNIT=SYSDA,SPACE=(CYL,(1,1)) //SYSIN DD * . . FLECS source program . . /* //stepname2 EXEC FORTHC,PARM.FORT='NOSOURCE' //SYSIN DD DSNAME=_&TEMP,DISP=(OLD,DELETE) .s 1 .f .hl 2 Using the Translator with FORTRAN(G) Several cataloged procedures have been established which simplify .x cataloged procedures the process of using FLECS together with FORTRAN(G). The procedure .x ^F^O^R^T^R^A^N(^G) names are given below together with the FORTRAN procedures to which they correspond. .s 1 .nf FLECSC FORTGC FLECSCL FORTGCL FLECSCLG FORTGCLG FLECSGO FORTGO .s 1 .f The reader is assumed to be familiar with the "FORTG" procedures. The FLECS procedures have been derived from the FORTG procedures by adding an initial procstep named FLECS which runs the FLECS translator and which passes the FORTOUT data set to the following step. Since error message from the FORTRAN compiler will contain the line number of the original FLECS source statement, the programmer will have little occasion to use the source listing produced by the FORTRAN compiler. For this reason, the source listing from FORTRAN has been suppressed by including a 'NOSOURCE' parameter for the compiler. .s 1 Example: Translating, compiling, linkage editing, and executing a FLECS program with previously compiled object decks and data. .s 1 .nf .tp 23 //jobname JOB accounting information //stepname EXEC FLECSCLG //FLECS.SYSIN DD * . . FLECS source program . . /* //LKED.SYSIN DD * . . required object decks . . /* //GO.SYSIN DD * . . input data . . /* .s 2 .f .lm 8 .rm 52 Note: To obtain the source listing from the FORTRAN compiler, replace the "EXEC" card above with the following: .s .nf .lm 0 .rm 60 //stepname EXEC FLECSCLG .s 2 .f In general, a FLECS run using one of the FLECS procedures is identical to a FORTRAN(G) run using the corresponding FORTG procedures with the following changes: .ls .le;Change the procedure name from FORTGxxx to FLECSxxx (exception: FORTGO becomes FLECSGO). .le;Change the SYSIN DD card from FORT.SYSIN to FLECS.SYSIN. .le;If desired, override the suppression of the source listing by including PARM.FORT='SOURCE' on the EXEC card as described above. .els .lc .ch RESTRICTIONS AND NOTES .LC .LM 0 .RM 60 .x RESTRICTIONS ^IF ^F^L^E^C^S WERE IMPLEMENTED BY A NICE, INTELLIGENT COMPILER THIS SECTION WOULD BE MUCH SHORTER. ^CURRENTLY, HOWEVER, ^F^L^E^C^S IS IMPLEMENTED BY A STURDY BUT NAIVE TRANSLATOR. ^THUS THE ^F^L^E^C^S PROGRAMMER MUST OBSERVE THE FOLLOWING RESTRICTIONS: .LS .RM 52 .LE ^F^L^E^C^S MUST INVENT MANY STATEMENT NUMBERS IN CREATING THE .x STATEMENT NUMBER ^F^O^R^T^R^A^N PROGRAM. ^IT DOES SO BY BEGINNING WITH A LARGE NUMBER (USUALLY 99999) 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\&. .LE ^THE ^F^L^E^C^S TRANSLATOR MUST GENERATE INTEGER VARIABLE NAMES. .x INTEGER VARIABLE ^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. ^USE "^^IMPLICIT#REAL#(A-H,J-Z)"\\ INSTEAD. .LE ^THE TRANSLATOR DOES NOT RECOGNIZE CONTINUATION LINES IN THE SOURCE .x CONTINUATION LINES FILE. ^THUS ^F^O^R^T^R^A^N STATEMENTS MAY BE CONTINUED, SINCE THE STATEMENT AND ITS CONTINUATIONS WILL BE PASSED THROUGH THE TRANSLATOR WITHOUT ALTERATION (^SEE SECTION 1.1). ^HOWEVER, ^&AN EXTENDED ^^FLECS\\ STATEMENT WHICH REQUIRES TRANSLATION MAY NOT BE CONTINUED\&. ^THE REASONS ONE MIGHT WISH TO CONTINUE A ^F^L^E^C^S 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 MULTI-LINE 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. .LE ^&^BLANKS ARE MEANINGLESS SEPARATORS IN ^F^L^E^C^S STATEMENTS; DON'T PUT THEM IN DUMB PLACES\&, LIKE THE MIDDLE OF IDENTIFIERS, OR KEY .x BLANKS WORDS, AND ^&DO\& USE THEM TO SEPARATE DISTINCT WORDS, LIKE ^^REPEAT\\ AND ^^UNTIL\\. .LE ^LET ^F^L^E^C^S INDENT THE LISTING. ^&^START ALL STATEMENTS IN COLUMN .x INDENTATION 7\& AND THE LISTING WILL ALWAYS REVEAL THE TRUE STRUCTURE OF THE PROGRAM (AS UNDERSTOOD BY THE TRANSLATOR, OF COURSE). ^ALTERNATIVELY, ON THE ^D^E^CSYSTEM-10 OR ^P^D^P-11, USE A TAB--_^^I--AS THE FIRST CHARACTER .x TABS .x ^D^E^Csystem-10 .x ^D^E^C ^R^T-11 OF EACH LINE FOLLOWED BY THE STATEMENT TEXT FOR CORRECT INDENTION BY THE ^^FLECS\\ TRANSLATOR. ^^NOTE:\\ AFTER SUCH A LEADING TAB CHARACTER, ^^FLECS\\ WILL ACCEPT ANY NON-ALPHABETIC (AND NON-"(") CHARACTER AS A VALID CONTINUATION CHARACTER, PLACING IT CORRECTLY IN COLUMN 6 OF THE RESULTING ^^FORTRAN\\ SOURCE FILE. .x continuation lines .LE ^AS FAR AS THE TRANSLATOR IS CONCERNED, ^^FORMAT\\ STATEMENTS ARE EXECUTABLE ^F^O^R^T^R^A^N STATEMENTS, SINCE IT DOESN'T RECOGNIZE THEM AS EXTENDED ^F^L^E^C^S STATEMENTS. ^THUS, ^&PLACE ^F^O^R^M^A^T STATEMENTS ONLY WHERE AN EXECUTABLE ^F^O^R^T^R^A^N 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. .S .NF ^INCORRECT#^EXAMPLES:######^CORRECTED#^EXAMPLES: .S .UC ##WHEN#(FLAG)#WRITE(3,3)###WHEN#(FLAG) 3#FORMAT(1H1)##############.##WRITE(3,3) ##ELSE#LINE=LINE+1#######3#.##FORMAT(1H1) ###########################...FIN ###########################ELSE#LINE=LINE+1 .S ##TO#WRITE-HEADER##########TO#WRITE-HEADER ##.##PAG=PAG+1#############.##PAG=PAG+1 ##.##WRITE(3,4)#PAG########.##WRITE(3,4)#PAG ##...FIN#################4#.##FORMAT(1X,I3) 4#FORMAT(1X,I3)############...FIN\\ .F .LC .LE ^THE TRANSLATOR, BEING SIMPLE MINDED, RECOGNIZES EXTENDED ^F^L^E^C^S STATEMENTS BY THE PROCESS OF SCANNING THE FIRST IDENTIFIER ON THE LINE. ^IF THE IDENTIFIER IS ONE OF THE ^F^L^E^C^S KEYWORDS ^^IF, WHEN, UNLESS, FIN\\, ETC., THE LINE IS ASSUMED TO BE A ^F^L^E^C^S STATEMENT AND IS TREATED AS SUCH. ^THUS, ^&^THE ^F^L^E^C^S KEYWORDS ARE RESERVED; DO NOT USE THEM AS VARIABLE NAMES\&. .x KEYWORDS ^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 "^W^H" FOLLOWED BY "^E^N" TO THE TRANSLATOR WHICH IS BLANK SENSITIVE, BUT LIKE "^^WHEN\\" TO THE COMPILER, WHICH IGNORES BLANKS. .LE ^IN SCANNING A PARENTHESIZED SPECIFICATION, THE TRANSLATOR .x PARENTHESES SCANS FROM LEFT TO RIGHT TO FIND THE PARENTHESIS THAT MATCHES THE INITIAL LEFT PARENTHESIS OF THE SPECIFICATION. ^THE TRANSLATOR, HOWEVER, IS IGNORANT OF ^F^O^R^T^R^A^N SYNTAX INCLUDING THE CONCEPT OF ^HOLLERITH CONSTANTS AND WILL TREAT ^HOLLERITH .x ^HOLLERITH PARENTHESES AS SYNTACTIC PARENTHESES. ^THUS, ^&AVOID PLACING ^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. ^ALTERNATIVELY, ^F^L^E^C^S IS CAPABLE OF RECOGNIZING ^F^O^R^T^R^A^N QUOTED LITERAL STRINGS; PARENTHESES EMBEDDED WITHIN LITERALS MAY BE USED SAFELY IN ALL CASES. .x LITERALS .S .NF ^INCORRECT ^EXAMPLE: ^CORRECTED ^EXAMPLES: .S ^^IF (J.EQ.1H() LP = '(' IF (J.EQ.LP)\\ OR ^^IF (J.EQ.'(')\\ .S .F ^NOTE THAT THIS RESTRICTION ALSO APPLIES TO ^HOLLERITH CONSTANTS CONTAINING SEMICOLONS WITHIN SPECIFICATIONS FOR ^^LOOP\\ STATEMENTS, WHEN IMPLEMENTED. .x SEMICOLONS .x ^L^O^O^P statement .LE ^THE ^F^L^E^C^S 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. .ELS .RM 60 .uc .lm 0 .rm 60 .ax FLECS KEYWORDS .x keywords .lm 8 .rm 52 .f Note: The following keywords are reserved for FLECS. Translation errors may occur if these words appear in any context other than those defined in the FLECS syntax. Their use as FORTRAN variable names should be avoided and is strongly discouraged. .lm 0 .rm 60 .nf .s 4 BREAK CONDITIONAL DEFINE DO ELSE END FALSE FIN IF INCLUDE LIST LOOP NEXT NOLIST OTHERWISE PAGE REPEAT RETURN SELECT STRING THEN TO TRUE UNLESS UNTIL WHEN WHILE .f .ax FLECS FLOWCHARTS .nf ^&Legend\&: .s [L] = Logical expression [E] = Expression (any type) [I] = DO iteration specification [_#] = Loop nesting level $ = Scope, 1 or more statements .s 4 ^&Alternative Structures\&: .x alternative structures .s 3 .x ^I^F statement .x ^U^N^L^E^S^S statement .x ^W^H^E^N...^E^L^S^E statement .x ^I^F...^T^H^E^N...^E^L^S^E statement WHEN ( [L] ) $1 ELSE $2 IF ( [L] ) $ UNLESS ( [L] ) $ or IF ( [L] ) THEN $1 ELSE $2 -------------- ------------------ -------------------- | | | v v v /-_\ T /-_\ F T /-_\ F <[L]>---+ <[L]>---+ +---<[L]>---+ _\-/ | _\-/ | | _\-/ | | v | v v v F | $ T | $ $1 $2 | | | | | | |<----+ |<----+ +---->+<----+ | | | v v v .pg ^&Alternative Structures (continued)\&: .x alternative structures .s 3 .x ^C^O^N^D^I^T^I^O^N^A^L statement .x ^S^E^L^E^C^T statement CONDITIONAL SELECT ( [E] ) . ( [L1] ) $1 . ( [E1] ) $1 . ( [L2] ) $2 . ( [E2] ) $2 . . . . . . . ( [Ln] ) $n . ( [En] ) $n ...FIN ...FIN -------------------- -------------------- | | v v /-_\ /-_\ / _\ T /[E]_\ T <[L1] >--->$1-->+ < .EQ.>--->$1-->+ _\ / | _\[E1]/ | _\-/ | _\-/ | | | | | F | | F | | v | v | /-_\ | /-_\ | / _\ T | /[E]_\ T | <[L2] >--->$2-->+ < .EQ.>--->$2-->+ _\ / | _\[E2]/ | _\-/ | _\-/ | | | | | F | | F | | ~ ~ ~ ~ : : : : ~ ~ ~ ~ | | | | v | v | /-_\ | /-_\ | / _\ T | /[E]_\ T | <[Ln] >--->$n-->+ < .EQ.>--->$n-->+ _\ / | _\[En]/ | _\-/ | _\-/ | | | | | F | | F | | |<-----------+ |<-----------+ | | v v .s 2 .f .lm 8 .rm 52 Note: OTHERWISE may be used in CONDITIONAL and SELECT statements as a final condition which is "always .TRUE.". .nf .lm 0 .rm 60 .pg ^&Repetitive Structures\&: .x repetitive structures .s 3 .x ^W^H^I^L^E statement .x ^R^E^P^E^A^T ^W^H^I^L^E statement WHILE ( [L] ) $ REPEAT WHILE ( [L] ) $ ------------------ ------------------------- | | | +-----+ v | F /-_\ T F /-_\ T | +---<[L]>---+ +---<[L]>-->| | _\-/ | | _\-/ | | _^ | | _^ | | | v | | v | | $ | | $ | | | | | | | +-----+ | +-----+ | | +-----+ +-----+ | | v v .s 3 .x ^U^N^T^I^L statement .x ^R^E^P^E^A^T ^U^N^T^I^L statement UNTIL ( [L] ) $ REPEAT UNTIL ( [L] ) $ ------------------ ------------------------- | | | +-----+ v | T /-_\ F T /-_\ F | +---<[L]>---+ +---<[L]>-->| | _\-/ | | _\-/ | | _^ | | _^ | | | v | | v | | $ | | $ | | | | | | | +-----+ | +-----+ | | +-----+ +-----+ | | v v .pg ^&Repetitive Structures (continued)\&: .x general ^L^O^O^P .x ^L^O^O^P statement .x ^R^E^P^E^A^T ^L^O^O^P statement .s 3 LOOP (init;[L];incr) $ REPEAT LOOP (init;[L];incr) $ ------------------------ ------------------------------- | | | +-----+ v | init v | init v | F /-_\ T F /-_\ T | +---<[L]>---+ +---<[L]>-->| | _\-/ | | _\-/ | | _^ | | _^ | | | v | | v | incr $ | incr $ | _^ | | _^ | | | | | | | | +-----+ | +-----+ | | +-----+ +-----+ | | v v .s 3 .x infinite ^L^O^O^P .x ^D^O statement [ REPEAT ] LOOP DO ( [I] ) $ ------------------ ------------------------- | | | +-----+ | | v Fail/-_\Suc | +-----+ +---<[I]>-->| _^ | | _\-/ | | | | _^ | | v | | v | $ | | $ | | | | | +-----+ | +-----+ | +-----+ | v .pg ^&Branch Statements\&: .x branch statements .x ^N^E^X^T statement .x ^B^R^E^A^K statement .s 3 NEXT [ [_#] ] BREAK [ [_#] ] ------------------ --------------------- | | v v /-_\ /-_\ +---< >----+ +---< >----+ | _\-/ | | _\-/ | | _^ | | _^ | | | | | | | | | NEXT v | BREAK v | |<=====$ |<===========$ | | | | | | | +------+ | +------+ | | +-----+ +-----+ | | v v .s 4 ^&Internal Procedures\&: .x internal procedures .s 3 procedure-name TO procedure-name $ ---------------- --------------------- | | +-----+ | | | v ---+ v procedure-name $ | <--+ | | | | | +-----+ v .s 2 .f .lm 8 .rm 52 Note: Place a RETURN, STOP, or CALL EXIT statement ahead of the first TO statement. .nf .lm 0 .rm 60 .f .ax FLECS SAMPLE PROGRAM .fg 4 .lm 8 .rm 52 Note: The following pages show the listing and FORTRAN output files for a "generalized" FLECS sample program. This program is ^¬\& intended to be compiled with any FORTRAN compiler, but rather it illustrates an example of each FLECS control structure and the corresponding FORTRAN statement(s) generated. .lm 0 .rm 60 .nf .s 4 ^&Legend\&: .s 1 [L] = Logical Expression [E] = Expression (any type) [I] = DO iteration specification $nn = Scope, 1 or more statements .pg ---------------------------------------- 00100 C 00200 C Sample FLECS Control Structures 00300 C 00400 C Alternative Structures 00500 C 00600 C "IF" - 1 alternative, do on .TRUE. 00700 C 00800 IF ( [L] ) $01 00900 C 01000 IF ( [L] ) 01100 . $02 01200 ...FIN 01300 C 01400 C "UNLESS" - 1 alternative, do on .FALSE. 01500 C 01600 UNLESS ( [L] ) $03 01700 C 01800 UNLESS ( [L] ) 01900 . $04 02000 ...FIN 02100 C 02200 C "WHEN" - 2 alternatives 02300 C 02400 WHEN ( [L] ) $05 02500 ELSE $06 02600 C 02700 WHEN ( [L] ) 02800 . $07 02900 ...FIN 03000 ELSE 03100 . $08 03200 ...FIN 03300 C 03400 C "CONDITIONAL" - N alternatives 03500 C 03600 CONDITIONAL 03700 . ( [L1] ) $09 03800 . ( [L2] ) 03900 . . $10 04000 . ...FIN 04100 . (OTHERWISE) $11 04200 ...FIN 04300 C 04400 C "SELECT" - N alternatives 04500 C 04600 SELECT ( [E] ) 04700 . ( [E1] ) $12 04800 . ( [E2] ) 04900 . . $13 05000 . ...FIN 05100 . (OTHERWISE) $14 05200 ...FIN .pg 05400 C 05500 C Repetitive Structures 05600 C 05700 C "DO" - FORTRAN iterative loop 05800 C 05900 DO ( [I] ) $15 06000 C 06100 DO ( [I] ) 06200 . $16 06300 ...FIN 06400 C 06500 C "WHILE" - test before, do if .TRUE. 06600 C 06700 WHILE ( [L] ) $17 06800 C 06900 WHILE ( [L] ) 07000 . $18 07100 ...FIN 07200 C 07300 C "REPEAT WHILE" - test after, do if .TRUE. 07400 C 07500 REPEAT WHILE ( [L] ) $19 07600 C 07700 REPEAT WHILE ( [L] ) 07800 . $20 07900 ...FIN 08000 C 08100 C "UNTIL" - test before, do if .FALSE. 08200 C 08300 UNTIL ( [L] ) $21 08400 C 08500 UNTIL ( [L] ) 08600 . $22 08700 ...FIN 08800 C 08900 C "REPEAT UNTIL" - test after, do if .FALSE. 09000 C 09100 REPEAT UNTIL ( [L] ) $23 09200 C 09300 REPEAT UNTIL ( [L] ) 09400 . $24 09500 ...FIN .pg 09700 C 09800 C "LOOP" - test before, do if .TRUE. 09900 C 10000 LOOP ($25;[L];$26) $27 10100 C 10200 LOOP ($28;[L];$29) 10300 . $30 10400 ...FIN 10500 C 10600 C "LOOP" - infinite form 10700 C 10800 LOOP $31 10900 C 11000 LOOP 11100 . $32 11200 ...FIN 11300 C 11400 C "REPEAT LOOP" - test after, do if .TRUE. 11500 C 11600 REPEAT LOOP ($33;[L];$34) $35 11700 C 11800 REPEAT LOOP ($36;[L];$37) 11900 . $38 12000 ...FIN 12100 C 12200 C "REPEAT LOOP" - infinite form 12300 C 12400 REPEAT LOOP $39 12500 C 12600 REPEAT LOOP 12700 . $40 12800 ...FIN 12900 C 13000 C Branch Statements 13100 C 13200 C "NEXT" - start next iteration of Nth loop 13300 C 13400 DO ( [I] ) 13500 . DO ( [I] ) 13600 . _^--NEXT 1 13700 _^--.--NEXT 2 13800 . ...FIN 13900 ...FIN 14000 C 14100 C "BREAK" - exit the Nth loop 14200 C 14300 DO ( [I] ) 14400 . DO ( [I] ) 14500 . v--BREAK 1 14600 v--.--BREAK 2 14700 . ...FIN 14800 ...FIN .pg 14900 C 15000 C Internal Procedures 15100 C 15200 C Internal Procedure references 15300 C 15400 procedure-name-1 15500 procedure-name-2 15600 STOP 15700 C 15800 C "TO" - Internal Procedure definitions 15900 C ---------------------------------------- 16000 TO procedure-name-1 $41 ---------------------------------------- 16100 TO procedure-name-2 16200 . $42 16300 ...FIN ---------------------------------------- 16400 END ---------------------------------------- Procedure Cross-Reference Table 16000 PROCEDURE-NAME-1 15400 16100 PROCEDURE-NAME-2 15500 (FLECS Version 22H(126)) ---------------------------------------- .pg 00800 IF ( [L] ) $01 01000 IF(.NOT.( [L] )) GO TO 99999 01100 $02 01600 99999 IF(.NOT.( [L] )) $03 01800 IF( [L] ) GO TO 99998 01900 $04 02400 99998 IF(.NOT.( [L] )) GO TO 99996 02401 $05 02402 GO TO 99997 02500 99996 $06 02700 99997 IF(.NOT.( [L] )) GO TO 99994 02800 $07 02900 GO TO 99995 03100 99994 $08 03700 99995 IF(.NOT.( [L1] )) GO TO 99992 03701 $09 03800 GO TO 99993 03801 99992 IF(.NOT.( [L2] )) GO TO 99991 03900 $10 04100 GO TO 99993 04101 99991 $11 04700 99993 IF(( [E1] ).NE.( [E] )) GO TO 99989 04701 $12 04800 GO TO 99990 04801 99989 IF(( [E2] ).NE.( [E] )) GO TO 99988 04900 $13 05100 GO TO 99990 05101 99988 $14 05900 99990 DO 99986 [I] 05901 $15 05902 99986 CONTINUE 06100 99987 DO 99984 [I] 06200 $16 06300 99984 CONTINUE 06700 99985 IF(.NOT.( [L] )) GO TO 99983 06701 $17 06702 GO TO 99985 06900 99983 IF(.NOT.( [L] )) GO TO 99982 07000 $18 07100 GO TO 99983 07500 99982 GO TO 99980 07501 99981 IF(.NOT.( [L] )) GO TO 99979 07502 99980 $19 07503 GO TO 99981 07700 99979 GO TO 99977 07701 99978 IF(.NOT.( [L] )) GO TO 99976 07800 99977 $20 07900 GO TO 99978 08300 99976 IF( [L] ) GO TO 99975 08301 $21 08302 GO TO 99976 08500 99975 IF( [L] ) GO TO 99974 08600 $22 08700 GO TO 99975 09100 99974 GO TO 99972 09101 99973 IF( [L] ) GO TO 99971 09102 99972 $23 09103 GO TO 99973 09300 99971 GO TO 99969 09301 99970 IF( [L] ) GO TO 99968 09400 99969 $24 09500 GO TO 99970 10000 99968 $25 10001 GO TO 99966 10002 99967 $26 10003 99966 IF(.NOT.([L])) GO TO 99965 10004 $27 10005 GO TO 99967 10200 99965 $28 10201 GO TO 99963 10202 99964 $29 10203 99963 IF(.NOT.([L])) GO TO 99962 10300 $30 10400 GO TO 99964 10800 99962 $31 10801 GO TO 99962 11100 99959 $32 11200 GO TO 99959 11600 99956 $33 11601 GO TO 99954 11602 99955 $34 11603 IF(.NOT.([L])) GO TO 99953 11604 99954 $35 11605 GO TO 99955 11800 99953 $36 11801 GO TO 99951 11802 99952 $37 11803 IF(.NOT.([L])) GO TO 99950 11900 99951 $38 12000 GO TO 99952 12400 99950 $39 12401 GO TO 99950 12700 99947 $40 12800 GO TO 99947 13400 99944 DO 99942 [I] 13500 DO 99940 [I] 13600 GO TO 99940 13700 GO TO 99942 13800 99940 CONTINUE 13900 99941 CONTINUE 13901 99942 CONTINUE 14300 99943 DO 99938 [I] 14400 DO 99936 [I] 14500 GO TO 99937 14600 GO TO 99939 14700 99936 CONTINUE 14800 99937 CONTINUE 14801 99938 CONTINUE 15400 99939 ASSIGN 99934 TO I99935 15401 GO TO 99935 15500 99934 ASSIGN 99932 TO I99933 15501 GO TO 99933 15600 99932 STOP 16000 99935 CONTINUE 16001 $41 16002 GO TO I99935 16100 99933 CONTINUE 16200 $42 16300 GO TO I99933 16400 END .f .ax FLECS DOCUMENTATION .LC .LM 0 .RM 60 .C (^AS OF ^DECEMBER, 1974) .S 2 ^BEYER, ^T.: ^F^L^E^C^S ^USERS ^MANUAL (^UNIVERSITY OF ^OREGON) .S .LM 4 ^CONTAINS A CONCISE DESCRIPTION OF THE ^F^L^E^C^S EXTENSION OF ^F^O^R^T^R^A^N AND OF THE DETAILS NECESSARY TO RUNNING A ^F^L^E^C^S PROGRAM ON THE ^^DEC\\SYSTEM-10 OR THE ^^IBM S/360\\ AT ^OREGON. .x ^^DEC\\SYSTEM-10 .x ^^IBM S/360\\ .S 2 .LM 0 ^BEYER, ^T.: ^F^L^E^C^S ^SYSTEM ^MODIFICATION ^GUIDE .S .LM 4 ^CONTAINS INFORMATION OF INTEREST TO ANYONE WHO WISHES TO INSTALL OR ADAPT THE ^F^L^E^C^S 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. .lm 0 .ax INDEX .lc .lm 12 .rm 60 .px ^E^C^S PROGRAM ON THE ^^DEC\\SYSTEM-10 OR THE ^^IBM S/360\\