Augustana University College

COMPUTING SCIENCE 370
Programming Languages


Fortran -- Syntactic Structures and Control Structures



Historical Overview

FORTRAN, the IBM Mathematical FORmula TRANslating System, was designed and implemented by a team at IBM led by John Backus.

Versions of FORTRAN
1954    FORTRAN I - specified
1956 FORTRAN I - implemented for the IBM 704
1958 FORTRAN II
1958 FORTRAN III
1962 FORTRAN IV - still an important dialect
1966 ANS FORTRAN    - ANSI standard FORTRAN IV (2 versions)
1977 FORTRAN 77
1990 FORTRAN 90

Structural Organization

Syntactic Structure


SYNTACTIC CONSISTENCY PRINCIPLE
Similar things should look similar.
Different things should look different.

Control Structures

GOTO
unconditional branch to a labelled statement
e.g., GOTO 400

IF
conditional execution of a statement
e.g., IF (X .EQ. A(I)) K=I-1
or IF (J.GT.3) GOTO 100

Computed GOTO
branch to one of several statements depending on the integer value of a variable
e.g., GOTO (10, 20, 30, 40), J

Assigned GOTO
branch to the statement whose address has previously been ASSIGNed to an integer variable
e.g., GOTO N, (10, 20, 30, 40)

DO loop
repeat statments up to a labelled CONTINUE statement, and increment a control variable by a fixed amount each time, terminating when the specified maximum is reached; e.g.,
      DO 100 J=1, N, 3
      A(J)=A(J)*2
100   CONTINUE


PORTABILITY PRINCIPLE
Avoid features or facilities that are dependent on a particular computer or a small class of computers.


STRUCTURE PRINCIPLE
The static structure of a program should correspond in a simple way to the dynamic structure of the corresponding computations. (E.W. Dijkstra)


DEFENSE IN DEPTH PRINCIPLE
If an error escapes detection by one line of defense (e.g., syntactic checking), it should be caught by the next line of defense (e.g., type checking).

PROBLEM in language design: foreseeing problems due to the interaction of features (e.g., between the syntax of GOTOs and the decision to use integer variables to hold the addresses of statements).


PRESERVATION OF INFORMATION PRINCIPLE
The language should allow the representation of information that the user might know and that the compiler might need.

Subprograms


SECURITY PRINCIPLE
No program that violates the definition of the language, or its own intended structure, should escape detection.

Activation Records

An activation record (AR) is a data structure which contains all of the information (the state) of one activation of a subprogram.

Subroutine S calls F(p, q)
Activation Unit (caller)     Activation Unit (callee)
AR CS
PAR
DL
IP
TMP
LOCAL
code
AR CS
PAR
DL
IP
TMP
LOCAL
code
Subroutine S Subroutine F(p, q)

Subprogram Call

  1. Save the state of the caller in the caller's AR.
  2. Place the parameters in the callee's AR.
  3. Set the dynamic link in the callee's AR.
  4. Activate the callee's AR at its first instruction.

Subprogram Return

  1. Use the DL to restore the state of the caller.
  2. Use the DL to branch to the return address.
  3. If the callee was a function, place the return value in a fixed location (a register or the callee's AR).

The two steps for return may be reversed if the caller is responsible for restoring its own state.

Copyright © 2000 Jonathan Mohr