home *** CD-ROM | disk | FTP | other *** search
- PP - Pascal Prettyprinting Program
-
- 11 October 1984
-
- - Jon Hueras and
- Henry Ledgard
- - Rick L. Marcus
-
- Toad Hall Tweak, reformat, 28 Nov 89
-
-
- What PP Does
- ------------
-
- PP takes as input a Pascal program or program fragment and reformats it
- according to a standard set of prettyprinting rules. The prettyprinted
- program is given as output. PP makes no attempt to detect or correct
- syntactic errors in your program. However, syntactic errors may result in
- erroneous prettyprinting.
-
- PP differs from some other prettyprinting programs in that it does not
- reformat your program "right down to every last semicolon." Such a
- philosophy requires formatting everything in a rigid fashion which is bound
- to be displeasing, or else it must provide you with a voluminous set of
- "options." Furthermore, such a scheme must do full syntax analysis of the
- program which means that it must be completely written and compilable. If
- you wish to prettyprint a program still under development, then you are out
- of luck.
-
- PP, on the other hand, implements a strategy which states that it is
- not necessary to impose more than a "minimum" set of restrictions, and the
- prettyprinter should yield to your discretion beyond this minimum. PP
- preserves blank lines and extra spaces you insert in the program as input,
- besides adding blank lines and extra spaces according to the rules for
- prettyprinting given below.
-
- General prettyprinting rules:
-
- 1. All statements and declarations begin on separate lines.
-
- 2. No input line may be longer than 80 characters. Any output line
- longer than 80 characters is continued on a separate line.
-
- 3. The keywords "BEGIN", "END", "REPEAT", and "RECORD" are forced to
- stand on lines by themselves (or possibly followed by supporting
- comments). In addition, the "UNTIL" clause of "REPEAT-UNTIL"
- statement is forced to start on a new line.
-
- 4. A blank line is forced before the keywords "PROGRAM", "PROCEDURE",
- "FUNCTION", "LABEL", "CONST", "TYPE", and "VAR".
-
- 5. A space is forced before and after the symbols ":=" and "=".
- Additionally, a space is forced after the symbol ":". Note that
- only "="s in declarations are formatted; "="s in expressions are
- ignored.
-
- 6. Spaces and blank lines already in your program are preserved by PP,
- which adds (but does not subtract) blank lines and spaces. You can
- improve the readability of your programs by taking advantage of this
- feature. However, this feature also means that you may sometimes
- have to manually de-indent (in your editor) after block structure
- changes.
-
- Indentation rules:
-
- 1. The body of a declaration is indented from the "LABEL", "CONST",
- "TYPE", or "VAR" keyword which heads it.
-
- 2. The bodies of "BEGIN-END", "REPEAT-UNTIL", "WHILE", "WITH", and
- "CASE" statements, as well as "RECORD-END" structures and "CASE"
- variants (to one level) are indented from keywords which head them.
-
- 3. An "IF-THEN-ELSE" statement is indented as follows:
-
- IF <expression>
- THEN <statement>
- ELSE <statement>
-
- When to Use PP
- --------------
-
- PP is especially useful to reformat a Pascal program or program
- fragment that you have typed without regard to formatting (such as entering
- every line left-justified to save time). Because the program need not be
- syntactically correct, PP provides the fastest means of obtaining a more
- readable version of your program.
-
- PP is best used to prettyprint a Pascal program already on a file or
- punched on cards. PP changes neither the cards nor the file used as input.
- Prettyprinting a program line-by-line as it is entered at a terminal is
- considerably less useful.
-
- How to Use PP
- -------------
-
- Type "PP" at the system command level followed by the old and new file
- names. If the new file already exists, it will be overwritten without
- warning. If the wrong number of file names are given, PP will print a
- message reminding the user of the correct system call.
-
- Examples
- --------
-
- 1. Reformat the same program under MS-DOS:
-
- PP prog1.pas prog1.new
- TYPE prog1.new
- ERASE prog1.pas
- RENAME prog1.new prog1.pas
-
- 2. Preview PP's output before writing to a file:
-
- PP prog.pas con
-
- 3. Remind oneself how to use PP:
-
- PP
-
- History
- -------
-
- PP prettyprints a Pascal program or program fragment given as input.
- It was originally named PRETTYPRINT and was written in Pascal by Jon Hueras
- and Henry Ledgard, University Computing Center and Computer and Information
- Science Dept., University of Massachusetts at Amherst, in August, 1976.
- (See "An Automatic Formatting Program for Pascal", by Jon Hueras and Henry
- Ledgard, Pascal Newsletter #6, page 70, November, 1976.)
-
- Small corrections were made to PRETTYPRINT by Charles Fischer, Dept.
- of Computer Science, University of Wisconsin, Madison, in 1977. PRETTYPRINT
- was modified for CDC-6000 Pascal by Rick L. Marcus, University Computer
- Center, University of Minnesota, in September, 1978, and was renamed PRETTY.
- Marcus also wrote this documentation.
-
- Peter Grogono adapted PRETTYPRINT to CP/M, using Pascal/Z. He also
- made several modifications and renamed it PP (date unknown). In 1984
- Willett Kempton adapted the Pascal/Z version to Turbo Pascal, which required
- only minor mods. The Turbo version uses a portable argument library
- "ARGLIB.PAS" to get file names, which makes it easier to adapt PP to other
- Pascal systems. The Turbo version has been tested under CP/M-80 and
- CP/M-86, and is believed to work without modification (other than
- recompilation) under MS-DOS. Kempton also adapted this documentation, from
- the CDC version, to apply to the microcomputer version.
-
- Toad Hall Tweak, 28 Nov 89:
- - Rewrote to compile under Turbo Pascal v5.0
- - Removed any nasty comments related to Turbo Pascal's
- "nonstandard" ways.
- - Replaced a bunch of array loading with typed array constants.
- - Threw in some TP5 functions (Inc, Dec, etc.)
- - Incorporated all the code in one file (instead of all the
- silly INC files).
-
- Notes:
- PP doesn't format Pascal code the way I like it! (I don't like
- new lines for each BEGIN, indented ENDs, etc.)
- However, someone asked for a Pascal formatter, so here it is.
-
- David Kirschbaum
- Toad Hall
- kirsch@arsocomvax.socom.mil