NAGWare f77 Transformational Tools

 

Index

DESCRIPTION
INTRODUCTION
LEXING
PARSING
ANALYSIS STAGE
FORTRAN OUTPUT
COMMENTS
SEE ALSO

 

DESCRIPTION

The following description relates to the NAGWare f77 Tools that systematically modify a Fortran 77 source file. These tools are:
nag_apt
Arithmetic Precision Transformer,
nag_chname
Name Changer,
nag_decs
Declaration Standardiser,
nag_lvi
Local Variable Initialiser,
nag_polish
Pretty Printer,
nag_profile
Profiler,
nag_struct
Restructurer.
 

INTRODUCTION

Before transformations are carried out, NAGWare f77 Tools first analyse the Fortran 77 source file to generate an internal representation of the program units upon which the transformations can be made. This process is exactly like the early stages of a compiler. The level of analysis used for each tool depends upon its level of sophistication.

A very brief description of the preliminary analysis stages of lexing and parsing follows for the benefit of the interested reader. An understanding of the concepts of lexing and parsing is not necessary to use NAGWare f77 Tools as these stages are effectively hidden from the user.

 

LEXING

Lexing is the analysis of the source code to identify the elements of the language called tokens. Tokens are the keywords, names, numbers etc. that make up the Fortran code. The result of lexing is a sequence of tokens called a token stream. Special tokens are added to the token stream to mark the position of comments, so that these can be output in the same place in the output program text, but see "Comments" below. All NAGWare f77 Tools invoke the lexing routines as the first, or in some cases only, stage of analysis.

 

PARSING

Parsing builds on the lexer analysis to create a parse tree and symbol table. In the process the parser carries out a syntactic analysis and ensures that the statements in the program unit are correctly formed and ordered.

A parse tree is a low level representation of a program unit in which the program elements are conceptually laid out in a two dimensional tree structure. Pointers logically connect the elements of the program. The parse tree of the trivial program:

      PROGRAM MAIN
      DO 10 I=1,10
      PRINT *,I
 10   CONTINUE
      END
is illustrated below.
ROOT--------MAIN--------PROGRAM-----Name=MAIN
                          |
                        DO----------Lbref=10
                          |           |
                          |         DOSPEC------Name=I
                          |                       |
                          |                     ICONST      1
                          |                       |
                          |                     ICONST      10
                          |
                        PRINT-------FMT=--------ASTERISK
                          |           |
                          |         Name=I
                          |
                        CONTINUE----Label=10
                          |
                        END

Another aspect of parsing is the construction of the symbol table. This is a data structure associated with the parse tree where the text of names and their attributes (type and information about usage) are stored.

A comment index is also constructed to ensure that comments remain associated with the same statement as in the input file.

 

ANALYSIS STAGE

nag_chname and nag_polish require relatively less understanding of the Fortran code and therefore work at the token stream level, see "Lexing" above. nag_apt, nag_decs and nag_struct require more understanding of the Fortran source and work at the parse tree level, see "Parsing" above.

Before any transformation is made the input source is analysed by the NAGWare f77 Tools lexer and, in some cases, parser. Hence the input to these tools must be syntactically correct Fortran 77 code as defined in nag_Fortran77. Deviations from this standard, in most cases will cause the input file to be rejected with error messages and the transformation will not be carried out.

 

FORTRAN OUTPUT

The transformational tools require to turn the internal representation of the transformed code back into Fortran text. If the tool works at the parse tree level the parse tree is first converted to a token stream. The only way of converting a token stream to Fortran text is by using the polishing routines which are invoked automatically by each transformer tool.

The polisher may be also be invoked directly using nag_polish in which case the output program is functionally identical to the input program with, possibly, layout and appearance changes specified by a polish options file (or defaults).

The other transformational tools listed above invoke the polisher to output the transformed Fortran text and hence a necessary prerequisite to obtaining the desired results is to create an appropriate polish options file using nag_polopt, if the built-in defaults are not acceptable.

 

COMMENTS

In normal circumstances comments are output in exactly the same position as in the input file. The exact position of comments in the final polished output may sometimes be changed very slightly relative to the original. Tools that delete and move statements must necessarily move comments associated with these statements. These tools are nag_decs, in rebuild mode, and nag_struct. The effect on the output code is fully documented.

 

SEE ALSO

nag_apt, nag_chname, nag_decs, nag_lvi, nag_polish, nag_profile, nag_struct, nag_Fortran77.

Copyright, Numerical Algorithms Group, Oxford, 1991-2001