www.delorie.com/gnu/docs/gcc/g77_665.html   search  
Buy the book!

Using and Porting GNU Fortran

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.2 Overview of Translation Process

The order of phases translating source code to the form accepted by the GBE is:

  1. Stripping punched-card sources (`g77stripcard.c')

  2. Lexing (`lex.c')

  3. Stand-alone statement identification (`sta.c')

  4. INCLUDE handling (`sti.c')

  5. Order-dependent statement identification (`stq.c')

  6. Parsing (`stb.c' and `expr.c')

  7. Constructing (`stc.c')

  8. Collecting (`std.c')

  9. Expanding (`ste.c')

To get a rough idea of how a particularly twisted Fortran statement gets treated by the passes, consider:

      FORMAT(I2 4H)=(J/
     &   I3)

The job of `lex.c' is to know enough about Fortran syntax rules to break the statement up into distinct lexemes without requiring any feedback from subsequent phases:


The job of `sta.c' is to figure out the kind of statement, or, at least, statement form, that sequence of lexemes represent.

The sooner it can do this (in terms of using the smallest number of lexemes, starting with the first for each statement), the better, because that leaves diagnostics for problems beyond the recognition of the statement form to subsequent phases, which can usually better describe the nature of the problem.

In this case, the `=' at "level zero" (not nested within parentheses) tells `sta.c' that this is an assignment-form, not FORMAT, statement.

An assignment-form statement might be a statement-function definition or an executable assignment statement.

To make that determination, `sta.c' looks at the first two lexemes.

Since the second lexeme is `(', the first must represent an array for this to be an assignment statement, else it's a statement function.

Either way, `sta.c' hands off the statement to `stq.c' (via `sti.c', which expands INCLUDE files). `stq.c' figures out what a statement that is, on its own, ambiguous, must actually be based on the context established by previous statements.

So, `stq.c' watches the statement stream for executable statements, END statements, and so on, so it knows whether `A(B)=C' is (intended as) a statement-function definition or an assignment statement.

After establishing the context-aware statement info, `stq.c' passes the original sample statement on to `stb.c' (either its statement-function parser or its assignment-statement parser).

`stb.c' forms a statement-specific record containing the pertinent information. That information includes a source expression and, for an assignment statement, a destination expression. Expressions are parsed by `expr.c'.

This record is passed to `stc.c', which copes with the implications of the statement within the context established by previous statements.

For example, if it's the first statement in the file or after an END statement, `stc.c' recognizes that, first of all, a main program unit is now being lexed (and tells that to `std.c' before telling it about the current statement).

`stc.c' attaches whatever information it can, usually derived from the context established by the preceding statements, and passes the information to `std.c'.

`std.c' saves this information away, since the GBE cannot cope with information that might be incomplete at this stage.

For example, `I3' might later be determined to be an argument to an alternate ENTRY point.

When `std.c' is told about the end of an external (top-level) program unit, it passes all the information it has saved away on statements in that program unit to `ste.c'.

`ste.c' "expands" each statement, in sequence, by constructing the appropriate GBE information and calling the appropriate GBE routines.

Details on the transformational phases follow. Keep in mind that Fortran numbering is used, so the first character on a line is column 1, decimal numbering is used, and so on.

21.2.1 g77stripcard  
21.2.2 lex.c  
21.2.3 sta.c  
21.2.4 sti.c  
21.2.5 stq.c  
21.2.6 stb.c  
21.2.7 expr.c  
21.2.8 stc.c  
21.2.9 std.c  
21.2.10 ste.c  

21.2.11 Gotchas (Transforming)  
21.2.12 TBD (Transforming)  

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003