FFFFFFFF OOOOOO RRRRRRR TTTTTTTT XX XX FF OO OO RR RR TT XX XX FF OO OO RR RR TT XXXX FFFFFF OO OO RRRRRRR TT XX FF OO OO RR RR TT XXXX FF OO OO RR RR TT XX XX FF OOOOOO RR RR TT XX XX FORTRAN ( Extended ) An Improved and Extended version of the OS/8 FORTRAN II compiler. Version 2.0C Developed by: George Gonzalez Hearing Research Lab University of Minnesota October 1978 Revised - June 1982 (C) 1977 University of Minnesota This document describes the salient differences between FORTX and the OS/8 Fortran II compiler. It assumes the reader is familiar with the FORTRAN IV language and with OS/8 Fortran II. See 'OS/8 Handbook', Chapter 7 for a description of OS/8 Fortran II and Chapter 8 for FORTRAN IV, or see the newer 'OS/8 Language Reference Manual' sections for Fortran II and Fortran IV. FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 Introduction. ------------- This writeup describes 'FORTX', an enhanced and improved version of the DEC OS/8 Fortran II compiler (FORT). The extensions include most of the useful features of Fortran IV (1977) which could be added within the limitations of the OS/8 Fortran II compiler, assembler, and loader. They include: Commands: DATA Logical and Block IF Statements Structured DO loops WHILE Statement INTEGER, LOGICAL, REAL Statements Operators: .LT. .GT. .LE. .GE. .EQ. .NE. .AND. .OR. .NOT. Constants: Logical, Hollerith, quoted, ASCII, and octal ( Plus many miscellaneous improvements described below ) The compiler remains downward-compatible with all standard OS/8 Fortran II programs, i.e. any standard OS/8 Fortran II program will compile correctly under FORTX, with one minor exception (see Strings). Users who have made use of some of the undocumented features of OS/8 Fortran II may have to make some minor changes. All known 'incompatibilities' of this sort are flagged by '**' in this document. This document has the following sections: Enhancements to Statements and New Features Improvements in Code Generation Miscellaneous Improvements Restrictions FORTX vs. FORTRAN IV Compiler Options Compiler Error Messages Run-time Error Checking FORTX Modification History Summary Known Bugs Installation -1- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 Multiple Sections. ------------------ The FORTX compiler can handle multiple SUBROUTINEs and FUNCTIONs during a single compilation. For example, a main program can have appended to it one or more subroutines or functions. However, these sections all use the same symbol table (can't have everything..). Therefore, a variable of the same name in two or more routines uses the same physical storage location. Be careful. Each routine must end with an END statement. A single object module is created which cannot be separated by the LIBSET module into separate library modules (it is treated as one module with multiple entry points). Statement Ordering. ------------------- +-----------------------+-----------------------+ ! COMMON ! SUBROUTINE ! ! DIMENSION ! FUNCTION ! ! INTEGER ! INTEGER FUNCTION ! ! LOGICAL ! LOGICAL FUNCTION ! ! REAL ! REAL FUNCTION ! ! EQUIVALENCE ! ! +-----------------------+-----------------------+ ! DATA ! +-----------------------------------------------+ ! "Executable Statements" ! +-----------------------------------------------+ ! END ! +-----------------------------------------------+ Note 1: Only one SUBROUTINE or FUNCTION statement is allowed per section. It can be anywhere before the first DATA or executable statement. This enables users to have a source file containing common and be able to compile it with a subroutine without having to combine the two sources to get the SUBROUTINE or FUNCTION statement first. Note 2: A given variable must be referenced by decalarative statements in the following order: First: COMMON Second: DIMENSION, INTEGER, LOGICAL, REAL Third: EQUIVALENCE Some examples of improper statement ordering are: DIMENSION VAR(3) INTEGER VAR EQUIVALENCE (VAR,WORD) COMMON VAR INTEGER WORD If COMMON is not declared first the order in which COMMON variables are allocated may not match the order in which they were declared (this is a restriction of the original Fortran II compiler). -2- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 Violations of the above ordering rules will produce 'INVALID STATEMENT' or 'INVALID VARIABLE DEFINITION/USAGE' compiler error messages. Comments. --------- A comment may be placed on any line by preceding it with an at sign. The compiler will ignore any text on a line after an at sign (@): IF ( CHAR .EQ. "$" ) RETURN @ End of file, return Also, any line with a '*' in columm 1 is treated as a comment. Continuations. -------------- A plus sign (+) in column 1 indicates that the line is a continuation of the previous line. Columns 1-6 are then ignored and the processing continues with column 7. Character strings. ------------------ Character strings may be denoted in 'H' format or in quoted string form. Examples: 16HTHIS IS A STRING 'THIS IS A STRING, TOO' Strings of 1 or 2 characters are treated as integer constants and may appear anywhere a integer is allowed: MINUS = 1H- MULT = '*' Strings of 3 to 6 characters are treated as real constants: HELLO = 5HHELLO BYE = 'BYE' Strings longer than 6 characters are a special case. They may only appear as an actual parameter. As an actual parameter the string appears to the calling routine as an array of packed (A2 or A6) characters, terminated by a zero character ('@'): CALL PRINT(17HPROGRAM COMPLETE.) **Note that FORTX does not zero-fill strings out to 6 characters like FORTRAN II. Routines that expect 6-character strings ( like IOPEN/OOPEN/CHAIN ) should be called with 6-character strings: Not: CALL CHAIN('A') ( FORTRAN II padded to 'A@@@@@' ) But: CALL CHAIN('A@@@@@') -3- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 **Also, FORTX strings of 1 or 2 characters are of type INTEGER, whereas FORTRAN II strings are all of type REAL. The temporary solution is to fill strings to 6 characters with zero characters ('@'). ASCII constants. ---------------- A full ASCII character may be denoted by placing the character in quotation (") marks. All characters have the parity bit set. Examples: Character: "A" "a" "Z" "z" Octal value: 301 341 332 372 Note that ASCII characters can only be input and output through user-written routines, as OS/8 Fortran II uses 6-bit characters for all user-level Input-Output. Octal constants. ---------------- An integer octal constant can be specified by following the number by the letter 'B'. Up to four octal digits may be specified: DATA ( MASK(I), I=1,4) / 0001B, 0010B, 0100B, 1000B / BELL = 207B Using non-octal digits (8 or 9) with a 'B' suffix is not detected as an error and results in an undefined value for the constant. The constant 4000B cannot be used. Logical constants. ------------------ The logical constants of 'true' and 'false' are symbolically represented as: .TRUE. and .FALSE. The internal representation of false is 12 '0' bits, an integer 0. True is represented as 12 '1' bits, an integer -1. Logical operators. ------------------ The logical operators are: .AND. .OR. .NOT. .AND. and .OR. perform the logical product and sum of their arguments as represented in the table below. .NOT. returns the logical negation of its one argument: -4- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 X Y X .OR. Y X .AND. Y .NOT. X --------------------------------------------------- F F F F T F T T F T T F T F F T T T T F The logical operators can also be used to perform Boolean operations on integers. The operators will perform 12-bit .AND. .OR. and .NOT. operations: CHAR = CHAR .AND. 177B @ Ignore parity bit WORD = HICHAR .OR. LOWCHAR @ Combine characters Logical variables. ------------------ A logical variable is a variable of type LOGICAL, as declared by the LOGICAL statement. The only operations defined on logical variables are: Logical assignment: MONDAY = .TRUE. Logical operations: WEEKDY = (.NOT. SUNDAY) .AND. (.NOT. SATDY) Logical comparison: IF ( WEEKDY ) WAKEUP = 7.00 Relational operators. --------------------- The standard Fortran IV relational operators are implemented: Relation Operator symbol -------- --------------- Equal .EQ. Not equal .NE. Greater than .GT. Less than .LT. Greater or equal .GE. Less or equal .LE. The relational operators take two integer or two real operands and return a LOGICAL result: LOGICAL FEVER, GENIUS FEVER = TEMP .GT. 98.6 GENIUS = IQ .GT. 140 The relational and logical operators, and the exponentiation operator have an alternate one-character representation, which is non-standard but have the same effect as the standard symbols. The operators, their alternate symbols, and their precedence are summarized below: -5- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 Operator Alternate Precedence -------- --------- ---------- ** ^ 7 Highest unary - 6 .NOT. \ 6 * 5 / 5 + 4 - 4 .EQ. : 3 .NE. # 3 .LT. < 3 .GT. > 3 .LE. $ 3 .GE. % 3 .AND. & 2 .OR. ! 2 Declarative statements. ----------------------- The variable declaration statements are used to declare a variable or function to be of a different type than is normally implied by the variable name. The statement is followed by a list of variables, arrays, and function names separated by commas. This list is herein called a D-list. Example D-lists: X, Y, Z [ scalar variables ] Q(10), W(5,5) [ arrays ] SINH, COSH, TANH [ external function names ] X, Q(10), W(5,5) [ combination ] INTEGER Statement ----------------- INTEGER D-list The INTEGER statement declares the items in the D-list to be of type integer, independent of their implicit type determined by the first character of their name. An array may be dimensioned in an INTEGER statement or a separate DIMENSION statement, but not both. REAL Statement -------------- REAL D-list The REAL statement declares the items in the D-list to be of type REAL. -6- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 LOGICAL Statement ----------------- LOGICAL D-list The LOGICAL statement declares the items in the D-list to be of type LOGICAL. FUNCTION Statement ------------------ The word FUNCTION can be optionally prefixed by the word INTEGER, LOGICAL, or REAL to declare the function as that type. DATA Statement. --------------- The DATA statement assigns initial values to variables and arrays: DATA var1,..., varn/val1,...,valn/, .etc.. The list of variables may consist of simple variables, array names, array elements, or implied array sections. For every simple variable or array element there must be a value of the same type: DATA X / 5.0 / DATA Z(5) / 9.9 / For every array name there must be enough values to fill the array, with the first subscript varying the fastest: DIMENSION LIST(5) DATA LIST / 1, 2, 3, 4, 5 / DIMENSION CHART(3,3) DATA CHART / 11, 21, 31, 12, 22, 32, 13, 23, 33 / For implied array sections there must be enough values to fill the specified section: DIMENSION X(10) DATA (X(I),I=1,4) / 1.0, 2.0, 3.0, 4.0 / A repeat factor can be used to set many elements of an array to the same value. The repeat factor is an integer and a '*' preceding the value to be repeated: INTEGER BIG(1000) DATA BIG / 500*1111, 500*1234 / The type of value must match the type of the variable. However character strings may be stored into any type of variable, up to 2 characters per integer, 6 characters per real variable: REAL STRING(2) -7- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 DATA STRING / 6HABCDEF, 'GHIJKL' / Variables in COMMON, EQUIVALENCE, or formal parameters cannot be preset by a DATA statement. The DATA statement requires 12K at compile-time. If the system has only 8K, then DATA is treated as an 'INVALID STATEMENT'. Once compiled, programs using the DATA statement do not have this restriction. Logical IF statement. --------------------- The logical IF statement conditionally executes one Fortran statement: IF ( condition ) statement 'statement' is executed only if 'condition' is TRUE. Examples: IF ( I .LT. 1000 ) I = I + 1 IF ( TEMP .GT. 98.6 ) CALL DOCTOR IF ( DELTA .LT. 0.00001 ) RETURN IF ( DAY .EQ. SAT .OR. DAY .EQ. SUN ) WEEKEND = .TRUE. 'statement' cannot be a declarative statement or Block IF, DO, or WHILE statement. It cannot have a statement number. Block IF Statement. ------------------- The Block IF statement is used to execute a block of statements if a given condition is true. The block of statements executed is from the statement following the IF up to the corresponding ENDIF statement: IF ( X > MAX ) THEN @ Swap Variables TEMP = X X = MAX MAX = TEMP ENDIF The indenting of the statements is optional, but recommended to clearly show the block of controlled statements. An optional ELSE statement introduces a block of statements to be executed if the condition is false: IF ( SPEED < 50 ) THEN RPM = 3000.0 GEAR = 3 ELSE RPM = 4000.0 GEAR = 4 ENDIF Another alternative is the ELSE IF statement. It continues the flow -8- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 of the current level IF statement and does not require an additional ENDIF statement to end the new IF condition. For example, the following two routines execute identically: IF (ICH .EQ. "A") THEN IF (ICH .EQ. "A") THEN CALL OPTNA CALL OPTNA ELSE ELSE IF (ICH .EQ. "B") THEN IF (ICH .EQ. "B") THEN CALL OPTNB CALL OPTNB ELSE ELSE CALL ERROR CALL ERROR ENDIF ENDIF ENDIF Block IF's may be nested 16 levels deep. The word 'THEN' after the if condition is optional. WHILE Statement. ---------------- The WHILE statement is used along with the ENDWHILE statement to delimit a block of statements to be repeatedly executed while a given condition is true: WHILE ( CHAR .NE. '$' ) @ SEARCH FOR '$' I = I + 1 CHAR = LINE(I) ENDWHILE If the condition is initially false, the block of statements is not executed at all. Structured DO. -------------- The structured DO loop works like a standard DO loop, but it is terminated by a ENDDO statement instead of by a specific statement number: DO ? I = 1, 10 X(I) = X(I) + Y(I) ENDDO The '?' is required to inform the compiler that this is a structured DO loop. -9- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 Improvements in Code Generation. -------------------------------- The index variable in a computed GO TO is always checked to be in the range of 1 to J, where J is the number of statement labels in the statement. If the index is in range, the normal branch occurs. If it is out of range, the program continues with the next sequential statement. The OS/8 Fortran II generated code would jump into undefined regions, never to return. The code generated for accessing arguments of a function or subroutine is much faster and smaller than the OS/8 Fortran II compiler code. The amount of code generated is independent of the number of arguments. If 16K is available at compile-time, the compiler stores FORMAT statements in a contiguous area of memory. This allows FORMAT statements to be of any length (not limited to 248 characters) and they do not waste memory due to paging. Up to 20% less memory is used by programs with many long FORMAT statements. The code generated for doing integer subtraction and unary minus is usually shorter. ** Branching to a FORMAT statement ( a guaranteed disaster in OS/8 Fortran II ) is diagnosed. The SABR assembler will flag any jumps to a FORMAT as 'undefined', and abort the assembly. A subprogram argument used as a DO-loop index works properly. OS/8 Fortran II would generate incorrect code if the DO-loop increment was 1. Subroutines and functions do not contain an unreachable call to the OPEN routine. Miscellaneous Improvements. --------------------------- All compiler error messages now print the sequential line number of the erroneous line. If 12K is available at compilation-time then duplicate or undefined statement numbers are diagnosed by the compiler instead of generating a cryptic error message late in SABR assembly. The compiler symbol table has been expanded about 20%, allowing the compilation of programs with more symbols. A RETURN statement in a main program acts as a STOP statement instead of causing a COMPILER MALFUNCTION message. A function need not set its returned variable. Specifing no input file now repeats the '*' prompt instead of generating a spurious error message. -10- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 Missing commas in implied-DO loops are diagnosed. A non-scalar variable or an expression on a computed GOTO is diagnosed. The format array in a read/write statement may be of type real. A labeled GOTO statement to the next line generates correct code. A overly-complex expression generates a diagnostic instead of crashing the compiler and perhaps the system. Placing a variable in COMMON more than once is diagnosed. If 16K is available at compilation time, then FORMAT statements without statement numbers are diagnosed. Most continuation processing restrictions were eased (most notably those involving CALL and IF statements). Restrictions. ------------- The size of internal compiler tables sets some numerical limits on FORTX programs. These limits are identical to or higher than the OS/8 Fortran II limits. A maximum of 265 different variable names, floating constants, 3-6 character strings, and arrays. A maximum of 128 strings longer than 6 characters, except in DATA statements, where there is no limit on the number of strings. A maximum string length of 247 characters. A maximum of 248 characters in one FORMAT statement. (No compiler limit if 16K is available to the compiler.) A maximum of 21 nested Do loops, block IF's and WHILE's. A maximum of 125 labels in a computed GOTO statement. No more than 62 actual parameters in a CALL or function argument list. A maximum of 63 unclosed left parentheses at any one time. -11- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 FORTX vs. FORTRAN IV -------------------- FORTX does not have the following FORTRAN IV features: 1) No DOUBLE PRECISION or COMPLEX types. 2) No ASSIGN # TO var statement. 3) No ASSIGNed GO-TO statement. 4) No L,T,P,G,D format specs. 5) No '0' or '+' format controls. 6) No binary or random-access Input/Output. 7) No BACKSPACE, REWIND, or ENDFILE. 8) No labeled or numbered COMMON. 9) No BLOCK DATA subprograms. 10) No EXTERNAL statement or routine name as a parameter. 11) No multiple equivalencing. 12) No 3-dimensional arrays. 13) No variable dimensions in subprograms. 14) No arithmetic statement functions. 15) No overlays (except thru CHAIN). -12- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 Compiler Options. ----------------- /C Disables array bounds checking. /D Enables 'debug' mode. Fortran statements with 'C$' in the first two columms are treated as compilable statements instead of as comments. This feature allows the conditional compilation of certain statements for debugging, or other purposes. /T Disables error traceback code. /V Prints the current version number and patch level of the FORTX compiler. Compiler Error Messages. ------------------------ In addition to the standard set of FORTRAN II compiler error messages, FORTX includes the following error messages: REDECLARATION A variable was declared twice. STRING TOO LONG Hollerith constant exceeded 256 characters. STRING TOO SHORT The end of statement was found before the Hollerith character count was satisfied. UNBALANCED QUOTES The end of statement was found before the quote terminating the string was found. TOO MANY STRINGS Over 128 long strings were encountered. INVALID DATA STATEMENT Syntax error in DATA statement, or incompatible types. DATA TABLE OVERFLOW Too much data is being defined. INVALID VARIABLE DEFINTION/USAGE The statements were not ordered properly. See 'Statement Ordering' section. IMPROPER NESTING Improperly nested DO, WHILE, or IF's. TOO MUCH NESTING More than 21 nested DO, WHILE, or IF's. MISSING ENDS At least one IF, WHILE, or DO did not have its corresponding closing ENDIF, ENDWHILE, ENDDO, or Statement #. DOUBLY DEFINED STATEMENT NUMBER Self-explanatory. STATEMENT NUMBER nnn WAS NEVER DEFINED Self-explanatory. -13- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 ARRAYS TOO LARGE Storage requirements exceeded. COMPILER TABLE OVERFLOW Too many statement numbers, symbols, or constants. Run-time Error Checking. ------------------------ Error Traceback --------------- FORTX normally emits extra instructions to provide a meaningful error traceback in case an error is detected at program run time. These extra instructions allow a helper program (DIAG) to diagnose the error and pinpoint the exact routine and line number where the error occurred. For example, the program below will generate the following output: 160 X = 0.0 CALL BADDY(X) END SUBROUTINE BADDY(Z) DO 105 I = 1,10 105 Z = ALOG(Z) / 3.14159 RETURN END ?LOGARITHM OF NUMBER <= 0.0? AT STATEMENT 105 OF ROUTINE "BADDY" CALLED FROM STATEMENT 160.1 OF MAIN PROGRAM. This error traceback is very handy when debugging a program, but a price is paid for the convenience as the traceback code makes most compiled programs about 10% longer than they would be without traceback. Specifying the /T option to the compiler instructs it to not generate instructions for a full error traceback. If the above program was compiled with the /T switch then the above error message would be less useful, as the exact line number of the error would not be available (DIAG prints 0 if it can't determine the correct line number). ?LOGARITHM OF NUMBER <= 0.0? AT STATEMENT 0 OF ROUTINE "BADDY" CALLED FROM STATEMENT 0 OF MAIN PROGRAM. The /T option should only be specified if the program will not otherwise fit into memory. Array bounds checking --------------------- The FORTX compiler normally generates extra instructions to check at program run-time that all array references (with subscripts) are within the dimensioned bounds of the array. If the array bounds are exceeded, a fatal error is generated: SUBS ERROR AT XXXXX -14- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 Or if DIAG is available: ?SUBSCRIPT OUT OF BOUNDS? AT STATEMENT XXX OF ROUTINE "YYYYY". In unusual cases it might be desireable to not check subscripts. Compiling with the /C option turns off all subscript range checking. This will shrink the size of the compiled program by about 5% but makes no measureable difference in program speed. -15- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 FORTX Modification History Summary. ----------------------------------- V1.2A Fixed optimizer bug in IF statement. V1.2B Compute memory size if not set by system. V1.2C Fixed DO nesting problem. V1.2D Fixed COMMON declaration problem. V1.2E Fixed /Z option for SPL compatiblity. Get around SABR problem by punching CPAGE 2 before punching EAP. V1.2F Only 6-bit character set legal except in 8-bit ASCII constant and in comments. Fixed statement number on WHILE problem. More thorough checking of statement ordering. V1.2G Equivalenced variables block reservation code had bug that sometimes caused insufficient room to be reserved thus causing destruction of following data or code. Diagnose non-dimensioned array reference (function) on left side of assignment statement. Subroutines no longer generate a symbol named "\". Fixed traceback not finding routine name problem by ensuring that name text is always on same page as entry point. Let SABR run a bit more efficiently by punching DUMMY statements and all storage cells after LAP. V2.0 Major restructuring of FORTX compiler with heavier usage of overlays. Multiple sections implemented. Up to 62 parameters now allowed in SUBROUTINE or FUNCTION. Diagnose non-scalar variable on computed GOTO. "+" in column 1 is continuation. SUBROUTINE and FUNCTION are no longer required to be the first statement. Get rid of traceback code generated for non-executable statements. Get around SABR problem by generating integer constants in storage rather than using literals on ARG statements in function and subroutine calls (SABR doesn't check for enough room for ARG literals). V2.0A Diagnose CALL of dimensioned variable. Fixed problem with multiple subroutines. V2.0B Implement ELSE IF statement. Allow statement number on ENDDO and ENDWHILE. Fix problem with DIMENSION statement in additional section clobbering floating point constant table. Fix some continuation problems. Don't generate code to subtract floating point 0.0 constant in logical comparison statement. V2.0C Fixed multiple FUNCTIONs clobbering function variable problem. -16- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 Known Bugs. ----------- The same variable in more than one DATA statement is not diagnosed. Only the first definition applies. A type REAL value used as a subscript is not diagnosed. Compiler errors should abort BATCH. Assignment to a non-dimensioned array element still not diagnosed (generates a call to a function). A source statement containing just blanks or TABs should be ignored instead of generating INVALID STATEMENT. The unit number on a WRITE or READ statement cannot be an expression. Neither unit number nor format variable can be parameters from the subroutine or function statement. If the conditionally executed statement on a structured IF statement is continued to the next line, the last character on the line must be a non-alphanumeric character. Otherwise the part of the statement that is on the same line as the IF is lost. -17- FORTX : Extended FORT II Compiler [ Version 2.0C ] 13-JUN-82 Installation. ------------- Installing FORTX in the system consists of copying the compiler, its library, and its error diagnosis program to device SYS: . This can be done by placing the FORTX distribution floppy in RX01 and typing: .COPY SYS: