FORTRAN 0 as --std=0

The source is the J. A. N. Lee copy of the preliminary report of 10 November 1954. The manual is not in this tree. Page numbers below are the printed footers, not the PDF page index. Expected test outputs describe this runtime’s interpretation of the proposal. They are not original-compiler results or evidence that a 704 ran FORTRAN 0.

--std=0 accepts arithmetic assignment, DIMENSION, EQUIVALENCE, a bare END, GO TO of a formula number or of a fixed-point variable, STOP with no octal field, the one-number DO, the three-number DO, the relational IF, list PRINT, READ, and PUNCH, the parenthesized tape and drum formulas on printed pages 19 and 20, RELABEL, RELATIVE CONSTANTS, and FREQUENCY. Statements from later dialects report “is not in FORTRAN 0”; invalid syntax may produce other diagnostics. SUM says “not in this FORTRAN 0 subset”.

What the report says, and what this mode does

Character set. Printed page 4 writes multiplication as × and exponentiation as xx (axxb for a to the power b). The same page notes a/b/c=(a/b)/c. Printed page 14 stacks the relational signs =, >, and >=. This mode uses * for multiplication, and both ** and xx for exponentiation. Blanks are ignored, so axxb and a xx b are the same power. A name is not split on any other letter. A name that is exactly XX stays a name. xx is rejected under --std=1 and --std=2. The relational signs are =, >, and >=. .EQ., .GT., and .GE. are extra spellings of those three signs. There is no <, <=, or /=. A single x is not multiplication, because × is not a card character.

Names. Printed page 4 allows one or two characters. A fixed-point name starts with i through n. This mode keeps the six-character FORTRAN I limit. A two-character cap would reject the names the rest of the compiler already accepts.

Fixed-point range. The constants section permits one to five decimal digits, with an optional sign. A fixed constant in the source, and an integer read by list READ, must lie in -32767..32767. That is the width this compiler already uses for a fixed word. I = 40000 is out of range even though 40000 has five digits.

Formula numbers. Printed page 10 requires a formula number less than 100,000. Columns 1-5 hold the number, so the range is 1..99999. Zero is not a formula number. --std=1 and --std=2 still require a statement number less than 32768. GO TO n reads a formula number from a fixed-point cell. That cell’s magnitude stays at most 32767, so the variable cannot name a formula above 32767. ASSIGN is not in this mode.

Cards. Printed page 25, section 13.D, allows about 65 characters, a formula number, and a continuation mark, and it ignores blanks. This mode keeps the FORTRAN I columns: 1-5, 6, 7-72, 73-80, and a C in column 1.

Expressions. The worked example in the expressions section is a sum of a quotient, a power times a factor, and a subtracted term. Addition sits outside multiplication and division, and xx binds tighter than those. The numbered precedence list on that page does not match the example, so the example is the one followed. The compiler uses that hierarchy: ** or xx, then * and /, then + and -.

Mixed mode. Printed pages 9 and 10, sections 8.C and 8.D. A fixed expression contains only fixed constants and variables. A floating expression contains only floating constants and variables, except a fixed argument of a built-in and a fixed variable or constant after **. Anything else is mixed. An assignment under --std=0 evaluates a mixed right-hand side in the mode of the left-hand name. Each leaf is converted before the operation, and a function result is converted after the call. The arguments stay in the built-in’s mode. The report does not name the functions in that exception, so no extra list is invented. A floating base stays floating when the exponent is one fixed variable or constant, and parentheses around that one value do not change it. A compound fixed exponent makes the power mixed. A pure floating value stored into a fixed name is computed in floating arithmetic and then truncated. A pure fixed value stored into a floating name is computed in integer arithmetic and then converted. --std=1, --std=2, a relational IF, a subscript, and a DO parameter still reject a mixed expression.

Subscripts. Printed page 8 defines a subscript as a fixed-point variable or a constant, and a subscript expression as a fixed-point expression of at most three terms. All but one term is a single variable or constant. One term may be a product of two subscripts. Parentheses are not permitted. Section 7, with the examples on printed page 9, allows one level of subscripted subscript. a(i(j)) and i(j(k)) are examples. a(i(j(k))) is not. This mode accepts those forms under --std=0, including i + j, n * i + j, 2 * n - i, and 100 - n * j. A constant subscript is at least 1. A leading sign is rejected. A product of three factors is rejected. Two product terms are rejected. The seven FORTRAN I forms are included, so they still compile. --std=1 and --std=2 still accept only those seven forms.

The report also says that all but one variable must be a relative constant. That rule is checked under --std=0. See RELATIVE CONSTANTS below. The wider form does not widen a DO parameter or a sequence bound. Those stay on the seven forms, including a zero addend such as J + 0 or J - 0. That addend is not a general subscript.

Functions. Section 4 begins at the foot of printed page 4 and says there is no specific list. The examples include sqrt and max. The FORTRAN II built-ins stay available. SUM, the summation sketch on printed page 10, is rejected. An arithmetic statement function is rejected. The report does not define one. The error is “statement functions are not in FORTRAN 0”.

DO. Printed page 11 gives both forms. do 10, 14, 50 i=4, 20, 2 runs formulas 10 through 14, then formula 50. The one-number example is do 17 i=1, 20. The prose then says the formula after formula 27 runs. That 27 disagrees with 17 and with the formal rule, so 27 is treated as a slip. After a one-number loop, the next formula is the one after the range. After a three-number loop, it is the third formula number.

The parameters on printed page 11 may be a fixed-point constant, a subscript, or a subscript expression. A constant may be zero. A subscript may be a non-subscripted fixed-point variable, or one subscripted fixed-point variable whose own subscripts are among the seven FORTRAN I forms. A subscript expression is one of those seven forms. Parentheses are rejected. A subscripted subscript is rejected. RELATIVE CONSTANTS is accepted. A DO parameter stays on the seven forms, and those forms have at most one variable, so the relative constant check does not reject them. The value is taken when the DO is entered. A later store into an array used as a parameter does not change the trip, and it is not “DO index or parameter redefined”. A leading sign is rejected, so a negative constant is not a parameter. A permitted form such as J - 2 can still evaluate to a negative step. --std=1 and --std=2 still accept only an unsigned constant or a non-subscripted fixed-point variable.

Section 10.A.vi says to begin the range and then increment, and to stop when the value is larger than the upper bound. Read strictly, the body runs at least once, and the test is the positive-step test. This mode keeps the FORTRAN II rule: a positive step with m1 already past m2 skips the range, and a negative step continues while the index is at least m2. A zero step is an error. A skipped trip leaves the index undefined.

Section 10.A.v says a control formula that refers to the DO itself increments the index and continues at the first formula of the range. This mode does that when the control formula is inside the range. A GO TO or a relational IF may name the DO. The step is the same one used for a normal trip, including a negative step, so the report’s “larger than the upper bound” is not applied on its own. When the new value is past the bound, a three-number DO goes to its third formula number and a one-number DO goes to the formula after the range. The index is then undefined. That exit does not also step an outer DO that shares the terminal. A GO TO of the DO from outside the range still starts at the initial value. --std=1 and --std=2 do not use this rule: the frame is dropped, and so is every frame nested inside it, and the DO starts again at the initial value.

A three-number DO may not share its terminal with another DO. A one-number DO still may. A transfer into either range is “transfer into a DO”. The 1956 extended-range return is not part of this mode.

Relational IF. Printed page 14 is If (N S N) F, F. Each N is a floating constant or variable, or a subscript, or a subscript expression. The sign is only =, >, or >=. Two formula numbers follow. This mode allows a full arithmetic expression on each side, compares them exactly, and requires both sides to have the same mode. The three-way arithmetic IF is not this formula and is rejected. When the relation holds, control goes to the first formula number. When it does not, control goes to the second.

GO TO and STOP. Printed page 14, section C, is Go to F. Section D is Stop. Printed page 23 also describes a go-to formula that reads go to n, where n is a fixed-point variable and its value is a formula number. This mode accepts that form under --std=0. n is not subscripted. At runtime the integer value is the statement number. Zero and a negative value are not statement numbers. An undefined variable, a missing statement number, a statement that is not executable, and a transfer into a DO use the same errors as a numeric GO TO. The FREQUENCY estimates are not a list of allowed targets. Computed GO TO, assigned GO TO, and ASSIGN stay rejected. --std=1 and --std=2 still require the assigned form, GO TO n, (list). Stop resumes at the next formula if the start button is pressed. This runtime exits, as FORTRAN II does, and STOP n is rejected.

RELABEL. The heading is on printed page 14. The form on the next page is Relabel V. V is a subscripted variable. Every subscript but one is the integer 1. The remaining subscript is a constant or a single fixed-point variable, and parentheses around it are rejected. That subscript names the element, row, column, or plane that becomes the new first. The words of that dimension are cycled. The element that had the chosen subscript becomes element 1, and the elements after it follow, wrapping to the start. A second RELABEL uses the labels as they then stand. A subscript of 1 on the chosen dimension does not move words.

Relabel a(3) on a vector of 7 elements makes the new a(1) the old a(3), the new a(6) the old a(1), and the new a(7) the old a(2). Relabel a(1, n, 1), with n equal to 3, on a 3 by 4 by 5 array cycles the second subscript. The old a(i, 3, j) is the new a(i, 1, j), and the old a(i, 2, j) is the new a(i, 4, j). A subscript outside the dimension is “subscript out of range”. Any other shape is rejected. A name that shares the cycled words sees them move. --std=1 and --std=2 reject the statement.

DIMENSION and EQUIVALENCE. Printed page 21 requires every array to be dimensioned, with constant subscripts. DIMENSION is accepted. Printed pages 21 and 22 give Equivalence (V, V, ...). V is a variable symbol, a scalar or an array name, and it is not subscripted. The names share storage from the first word. A set of scalars occupies one word. A set that contains arrays occupies the largest array, and the smaller names occupy its beginning. This mode accepts that sentence under --std=0. A subscript on a name is “a FORTRAN 0 EQUIVALENCE name is not subscripted”. --std=1 and --std=2 still use the later offset form, EQUIVALENCE (A(k), B).

The same pages state a type-1 and type-2 condition on the order of execution. The report gives it as the programmer’s rule for when the sentence may be written, and it gives no check. This mode does not diagnose that condition. COMMON stays absent under --std=0.

RELATIVE CONSTANTS. Printed page 23. The form is Relative constants N[, N, N, ...]. Each N is a fixed-point variable and is not written with a subscript. An array name designates every element. The designation belongs to the program, so the sentence may follow a use of the name. A floating name is rejected. --std=1 reports that the statement is not in FORTRAN I. --std=2 reports that it is not in FORTRAN II.

Printed page 8 requires that all but one of the variables in a subscript expression be a relative constant. This mode allows at most one variable that is not a relative constant. A repeated name counts once. A subscripted variable counts as its array at the level that contains it, and its own subscripts are checked as separate expressions. A subscript made only of constants, or only of relative constants, is accepted. The check runs only under --std=0, and only after the shape check, so a bad shape stays “illegal subscript”.

FREQUENCY. The heading is section 12.C on printed page 22. The body is on printed page 23. The general form is Frequency E[, E, E...]. An estimate is a parenthesized list of unsigned integers. Two numbers are the DO estimate: the formula number and the average number of repetitions. Three numbers are the IF estimate: the formula number, how often the condition is satisfied, and how often it is not. The same three-number shape is also a GO TO estimate with one pair. A longer odd count is the GO TO estimate: the formula number, then pairs of a value of n and how often n takes that value. The parser accepts the shape and does not choose between the IF reading and the one-pair GO TO reading. Any other count is rejected. The numbers are not stored. They do not have to be statement numbers, and they do not limit a later GO TO. The statement is not executable, so the results of a program do not change.

The printed GO TO example disagrees with its own gloss, and both are kept as printed. The estimate is (2, 13, 100, 14, 10, 15, 1000). The gloss says n takes the value 13 one hundred times, the value 14 ten times, and the value 14 one thousand times. The prose says n may take the values 14, 15, and 16. This mode does not repair either reading.

Each number is an unsigned fixed constant in 0..32767, at most five digits. A sign is rejected. --std=1 and --std=2 still accept any tail and ignore it.

List input and output. Printed pages 17 to 19 give read L, punch L, and print L, with no format number. A bare array name is printed in column-major order. That is the report’s default: the first subscript varies fastest. A parenthesis that starts a list item is a sequence specification. The arrays come first, then one to three clauses. A clause is S = N, N or S = N, N, N. The third N is the increment, and an omitted increment is 1. The first clause varies least often. Each array in the group has one subscript for every clause, and that subscript is a fixed-point variable. N is a FORTRAN 0 DO parameter. A leading sign is rejected. The index is left at its last value. An empty trip does not change it. A zero increment is an error. PRINT and PUNCH may contain constants. READ may not. The error is “a constant is not allowed in a READ list”. A FORMAT statement is still rejected. PUNCH uses the same printer as PRINT: one value per line on standard output, an integer in decimal, a real with a decimal point. READ takes free fields from standard input, separated by a comma or by whitespace. An integer field may not contain a decimal point or an exponent. A real field must contain a decimal point, and the value is then stored as a 704 word. An implied DO under --std=1 and --std=2 is a different form: one index, and that index becomes undefined when the list finishes.

Tape and drum. Tape formulas are on printed page 19. Drum formulas, and section K, are on printed page 20. The examples continue on printed page 21. READ TAPE (N) L and READ INPUT TAPE (N) L share one description. WRITE TAPE (N) L and WRITE OUTPUT TAPE (N) L are the matching writes. END FILE (N), REWIND (N), and BACKSPACE (N) take only the unit. READ DRUM (N, M) L and WRITE DRUM (N, M) L follow. There is no comma between the closing parenthesis and the list. The list is required. A constant is forbidden on a tape read and on a drum read, and is allowed on a write. The page does not split the two tape spellings into BCD and binary, so both use one binary record. FORTRAN I and II keep the comma syntax and the FORMAT distinction.

N is a unit number or a fixed-point variable. The report states no unit range. This runtime keeps the machine it already uses: tape units 1 through 10 and drum units 1 through 8, checked when the statement runs.

M is a drum location or a fixed-point variable, from 1 to 2048. Location 1 is the first word and 2048 is the last. A transfer that would pass the last word is “drum address out of range” and does not wrap. The read walks the list once. A value stored earlier in that list is visible to a later bound, and the sequence index moves only during that walk. --std=1 and --std=2 still use a 0-based address and still wrap at 2048.

Section K applies when a drum list gives a sequence specification with an array. The labeled correct example is a, (b(i,j,k) i=7, 10 j=1, 50, k=1, 50). The where-clause says that 50 is the maximum for i and j. In the formula the full ranges are on j and k, so the check uses each subscript’s DIMENSION maximum and does not follow that sentence’s names. That example uses the array’s own subscript order, and the free range is the first subscript. The prose asks for the opposite order and says that only the last subscript may be arbitrary. Those words reject the labeled example, so they are not applied. The same reading dropped the 27 in the DO example whose formula is numbered 17. A drum sequence names one array. The clauses follow the array’s subscript order. The increment is 1, or it is omitted. The first subscript may use any bounds already legal on a sequence. Each later subscript runs from the constant 1 to that subscript’s DIMENSION maximum. A subscripted name with no sequence specification stays legal. Separate parenthesis groups are separate items, and each may name one array. The running test uses DIMENSION B(10, 2, 2) and (B(I, J, K), I = 7, 10, J = 1, 2, K = 1, 2). It does not move the 50-wide page example.

A bare WRITE is not a statement of this report. The error is “a bare WRITE is not a FORTRAN statement”.