SF3PRETTY 1L "29 April 1994" "University of Utah "

Table of contents


NAME

sf3pretty - SFTRAN3 and Fortran lexical analyzer

SYNOPSIS

sf3pretty [-a] [-bx] [-cx] [-debug] [-d#] [-h] [-i#] [-k#,#,...] [-lkeystring] [-m] [-s#] [-ukeystring] <infile >outfile

DESCRIPTION

sf3pretty is the beginning of a powerful SFTRAN3 program prettyprinter. Since SFTRAN3 is a superset of Fortran 66 and Fortran 77, it will handle Fortran code as well. Because it is based on a rigorous language grammar, it can do a correct job of prettyprinting, since every language token is recognized. Most other prettyprinters, particularly for Fortran, attempt only limited recognition of the input. sf3pretty at present has no facilities for putting statement numbers in order, changing precision, or regrouping FORMAT statements; use pretty(1L) for that job. Such features, and many others, will be added as it evolves. However, it can convert DEC-style tabs to blanks, regularize letter case and token spacing, and supply control structure indentation.

In particular, it can be applied to the output of pretty(1L) to supply indentation for Fortran 77 block-IF statements, which pretty(1L) presently does not recognize as candidates for indentation. It is at least 20 times faster than pretty (1L), and processes about 275 lines/sec on a Sun 3/50 (15MHz Motorola 68020) system, so it can be routinely applied to code without serious time penalties.

Following the conventions of DEC Fortran compilers, an initial tab on a line blank-fills through column 6 if the next character is not a digit, and otherwise fills through column 5, placing the following digit in column 6 as a continuation character. Tabs embedded in lines are expanded by blank padding through the next column which is a multiple of 8 (thus preserving layout in comments). The output contains no tab characters.

In order to preserve neat indentation according to control structure level, long character strings are split, preferably at a blank. In executable statements, the concatenation operator, //, is used to merge them back into one string (usually at compile time). In FORMAT statements, comma separators are inserted. In DATA statements, where string expressions are not permitted by Fortran 77, the break is made at column 72, and the same string continues in column 6 of the next line. Because some compilers (erroneously) fail to pad input statements to column 72 before merging continuation lines, trailing blanks on a line in such a split string can be lost. To prevent this, if column 72 is blank when a string is wrapped, a hyphen will be output in column 73; it will be ignored by the compiler, but will protect against erroneous string truncation. Otherwise, trailing blanks are trimmed from the output.


LANGUAGE RECOGNIZED

The lexical analyzer used by sf3pretty recognizes the complete Fortran 66 and 77 languages as defined in the ANSI Fortran X3.9-1966 and ANSI Fortran X3.9-1978 Standards. It also recognizes the SFTRAN3 language keywords and directives as described in the SFTRAN3 Programmer's Reference Manual by Charles L. Lawson and John A. Flynn (JPL Document No. 1846-98, 1978, Jet Propulsion Laboratory, Pasadena, CA).

To increase its utility, the analyzer also recognizes numerous language extensions present in commonly-used Fortran compilers. These are summarized in the following table. Note that some extensions are supported by multiple vendors.

Vendor

CDC
<letter>=, Rw, and nVw.d FORMAT items, nRxxxx right-adjusted Hollerith constant, "xxx" quoted strings
Cray
n/ FORMAT item
DEC
ACCEPT, DO ... ENDDO, IMPLICIT NONE, INCLUDE, REREAD, and TYPE statements, E, F, G, I, Ow.d, Q, Zw.d, and $ FORMAT items, long variable names, $ and % in variable names, tabbed source format, lower-case source format
IBM
&nnn alternate return specifier, NAMELIST I/O
UNIX
B, P, nR, SU, T, and nT FORMAT items

OPTIONS

The order and letter case of command options is not significant; sf3pretty has been designed to run on multiple operating systems, most of which ignore letter case.
-a
Display author and copyright information on stderr.
-bx
Set the comment character to x, which must be `*', `C', or `c'. If not given, the original comment characters are preserved.
-cx
Set the statement continuation character (for column 6) to x, which may be any character in the Fortran character set (upper-case letters, digits, space, = + - * ( ) / , . $ ' : ), except space or 0. The default is -cX.
-d#
Set optional space-deletion bits (see -s# below). A value -d0 removes internal defaults, so that input space will be exactly preserved in the output, except at the beginning of lines, which are indented according to the setting of the -i# switch. The default is -d0xffffffff, which will remove all whitespace around non-alphanumeric tokens (the default -s# switch setting restores appropriate spacing).
-h
Convert Fortran 66 Hollerith strings (like 6HO'hara) to Fortran 77 quoted character strings (like 'O''hara').
-i#
Set the statement indentation value to #. Values in the range 2..5 are suggested. The default is -i5 if this switch is not specified.
-k#,#,...
Set the declaration columns to the indicated values; the defaults are equivalent to -k26,39,52,65 matching the output of the Extended PFORT Verifier (pfort(1L)) declaration file. Commas, colons, semicolons, or whitespace may separate the numbers. If whitespace separators are used, the argument must be quoted to prevent it from being interpreted as multiple arguments.

If a negative number appears in the list, then all columns from the preceding number to the absolute value of the negative one are declaration columns. The shorthand of, say, -k26,-72 says that any column in the range 26 through 72 is a declaration column; in other words, variables will appear successfully without intervening space.

-lkeystring
Output in lower case the tokens of the type specified by the keystring value. The characters in the keystring may be in either letter case, and may occur in any order (even repeated). They may be one or more of the following:
C
constants (except quoted and Hollerith strings)
D
SFTRAN3 directives
F
FORMAT fields
I
Fortran INCLUDE statements
K
keywords
O
operators
V
variables, subroutines, functions, and other user-defined names

Letter case of comments and character strings is never altered. By default, input letter case is preserved. However, -ucdfikov could be used to convert all but comments and strings to upper case (ANSI standard), and -lCDFKIOV would correspondingly convert to lower case. If both switches are given with the same letter options, the last one specified is used.

If no keystring is specified, CDFKOV is assumed; this selects all options except the one affecting Fortran INCLUDE statements. Because they contain file names whose letter case may be significant on some operating systems, they are never modified unless explicitly requested.
-m
Display dynamic memory usage on stderr on termination.
-s#
The -d# and -s# switches set a group of bit flags for selecting spacing options. The -s switch selects space insertion, and the -d switch selects space deletion. Spacing is left unchanged for those tokens for which no option is given. The deletion values apply only to whitespace tokens present in the input stream; they do not remove space inserted by the spacing values.

The value is selected by or'ing together any of the following values, or by specifying the desired values in separate options, and it may be specified in decimal, octal (0nn), or hexadecimal (0xnnn):

0x00001
=
0x00002
+ -
0x00004
* /
0x00008
logical operators (.and., .eqv., .neqv., .not., .or., .xor.)
0x00010
relational operators (.eq., .ge., .gt., .le., .lt., .ne.)
0x00020
logical constants (.false., .true.)
0x00040
comma
0x00080
SFTRAN3 structure labels
0x00100
SFTRAN3 inline comments
0x00200
concatenation operator (//)
0x00400
exponentiation operator (**)
0x00800
colon
0x01000
ampersand
0x02000
left parenthesis
0x04000
right parenthesis
0x08000
semicolon
0x10000
keywords
0x20000
user-defined names

If a value 0 is specified, the internal defaults are cleared, so that original spacing will be preserved. The default value is -s0x183fb.

-ukeystring
Specify token types to be converted to upper case (see -l above).

To support consistent prettyprinting style, it is convenient to be able to supply standardly-used options in a default startup file. This file is called .sf3pretty on UNIX systems, or sf3pretty.opt on others, and it is searched for in the current directory, or if not found there, in the login directory. If the file is found, up to 72 characters of its first line are read and parsed into command line options. These should not be protected by shell quotes; for example, the command line argument '-c*' should appear simply as -c*.


FILES

Standard input and standard output.
./.sf3pretty
default option file
~/.sf3pretty
default option file

SEE ALSO

fortlex(1L), ftnchek(1L), pfort(1L), pretty(1L), sf3(1L), sf3lex(1L), sf3xref(1L), xsf3(1L).

BUGS

Although a complete grammar for SFTRAN3 and Fortran 66/77 is implemented, with extensions from DEC, UNIX, Cray, CDC, and IBM Fortran, the constraints of doing this with a machine-generated lexical analyzer are that FORMAT is a reserved word. Use of the word FORMAT as a variable name may lead to incorrect output formatting; however, since no tokens are discarded, the output should still compile correctly.

AUTHOR

Nelson H. F. Beebe
Center for Scientific Computing
Department of Mathematics
University of Utah
Salt Lake City, UT 84112
USA

Tel: +1 801 581 5254 FAX: +1 801 581 4148

Email: beebe@math.utah.edu