home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Oakland CPM Archive
/
oakcpm.iso
/
sigm
/
sigmv062.ark
/
PRETTY.DOC
< prev
next >
Wrap
Text File
|
1984-04-29
|
10KB
|
225 lines
(*
PROGRAM TITLE: PASCAL PRETTYPRINTING PROGRAM
AUTHORS: JON F. HUERAS AND HENRY F. LEDGARD
COMPUTER AND INFORMATION SCIENCE DEPARTMENT
UNIVERSITY OF MASSACHUSETTS, AMHERST
(EARLIER VERSIONS AND CONTRIBUTIONS BY RANDY CHOW
AND JOHN GORMAN.)
BUGS CORRECTED BY : CHARLES FISCHER
DEPARTMENT OF COMPUTER SCIENCE
UNIVERSITY OF WISCONSIN, MADISON
1977
MODIFICATIONS : ( FOR GEORGIA TECH CYBER 70 (1979))
PETER N. WAN
INFORMATION AND COMPUTER SCIENCE
GEORGIA INSTITUTE OF TECHNOLOGY
ATLANTA, GEORGIA 30332
( FOR UCSD PASCAL V1.5 (1979) )
FRANCIS J. MONACO
2679 LOWELL DRIVE
MARIETTA, GEORGIA 30060
404-424-1460
SPECIAL NOTE ON CURRENT VERSION: THE PROGRAM CURRENTLY RUNS UNDER UCSD
PASCAL; THE MODIFICATIONS TO THE BELOW PROGRAM SUMMARY INCLUDE:
1) PROGRAM PROMPTS FOR DISK FILE IN LOGICAL UNIT #5; USER SHOULD
RESPOND WITH FIRST PART OF FILE NAME ( TO BE PRETTYPRINTED )
AS --> MYPROG----- NOT #5:MYPROG.TEXT !!!
2) PROGRAM PROMPTS FOR DISK FILE FOR PRETTYPRINTED PGM; AGAIN,
USER SHOULD RESPOND WITH FIRST PART OF FILE NAME ONLY.
3) PROGRAM NOW ACCEPTS UPPER/LOWER CASE INPUT AND TRANSLITERATES
ALL TO UPPER CASE ( TO EASE PORTABILITY CONSIDERATIONS ).
NOTE: QUOTED STRINGS ARE NOT TRANSLITERATED; ALSO,
PROGRAM CONVERTS '{' TO '(*' AND '}' TO '*)' FOR COMMENTS.
4) PROGRAM BUILDS PRETTYPRINTED DISK FILE WHILE SIMULTANEOUSLY
ECHOING OUTPUT TO CRT ( IN REAL TIME ).
5) PROGRAM WILL LEAVE UCSD SPECIAL RESERVED WORDS LIKE "SEGMENT",
"UNIT", ETC. ALONE.
6) PRETTYPRINTED OUTPUT IS 79 CHARACTERS PER LINE (SEE MAXLINESIZE)
PROGRAM SUMMARY:
THIS PROGRAM TAKES AS INPUT A PASCAL PROGRAM AND
REFORMATS THE PROGRAM ACCORDING TO A STANDARD SET OF
PRETTYPRINTING RULES. THE PRETTYPRINTED PROGRAM IS GIVEN
AS OUTPUT. THE PRETTYPRINTING RULES ARE GIVEN BELOW.
AN IMPORTANT FEATURE IS THE PROVISION FOR THE USE OF EXTRA
SPACES AND EXTRA BLANK LINES. THEY MAY BE FREELY INSERTED BY
THE USER IN ADDITION TO THE SPACES AND BLANK LINES INSERTED
BY THE PRETTYPRINTER.
NO ATTEMPT IS MADE TO DETECT OR CORRECT SYNTACTIC ERRORS IN
THE USER'S PROGRAM. HOWEVER, SYNTACTIC ERRORS MAY RESULT IN
ERRONEOUS PRETTYPRINTING.
INPUT FILE: (PROMPTED) - A FILE OF CHARACTERS, PRESUMABLY A
PASCAL PROGRAM OR PROGRAM FRAGMENT.
OUTPUT FILES: (PROMPTED) - THE PRETTYPRINTED PROGRAM.
PASCAL PRETTYPRINTING RULES.
.[ GENERAL PRETTYPRINTING RULES ]
1. ANY SPACES OR BLANK LINES BEYOND THOSE GENERATED BY THE
PRETTYPRINTER ARE LEFT ALONE. THE USER IS ENCOURAGED, FOR THE
SAKE OF READABILITY, TO MAKE USE OF THIS FACILITY.
IN ADDITION, COMMENTS ARE LEFT WHERE THEY ARE FOUND, UNLESS
THEY ARE SHIFTED RIGHT BY PRECEEDING TEXT ON A LINE.
2. ALL STATEMENTS AND DECLARATIONS BEGIN ON SEPARATE LINES.
3. NO LINE MAY BE GREATER THAN 72 CHARACTERS LONG. ANY LINE
LONGER THAN THIS IS CONTINUED ON A SEPARATE LINE.
4. THE KEYWORDS "BEGIN", "END", "REPEAT", AND "RECORD" ARE
FORCED TO STAND ON LINES BY THEMSELVES (OR POSSIBLY FOLLWED BY
SUPPORTING COMMENTS).
IN ADDITION, THE "UNTIL" CLAUSE OF A "REPEAT-UNTIL" STATE-
MENT IS FORCED TO START ON A NEW LINE.
5. A BLANK LINE IS FORCED BEFORE THE KEYWORDS "PROGRAM",
"PROCEDURE", "FUNCTION", "LABEL", "CONST", "TYPE", AND "VAR".
6. 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.
[ INDENTATION RULES ]
1. THE BODIES OF "LABEL", "CONST", "TYPE", AND "VAR" DECLARA-
TIONS ARE INDENTED FROM THEIR CORRESPONDING DECLARATION HEADER
KEYWORDS.
2. THE BODIES OF "BEGIN-END", "REPEAT-UNTIL", "FOR", "WHILE",
"WITH", AND "CASE" STATEMENTS, AS WELL AS "RECORD-END" STRUC-
TURES AND "CASE" VARIANTS (TO ONE LEVEL) ARE INDENTED FROM
THEIR HEADER KEYWORDS.
3. AN "IF-THEN-ELSE" STATEMENT IS INDENTED AS FOLLOWS:
IF <EXPRESSION>
THEN
<STATEMENT>
ELSE
<STATEMENT>
GENERAL ALGORITHM
THE STRATEGY OF THE PRETTYPRINTER IS TO SCAN SYMBOLS FROM
THE INPUT PROGRAM AND MAP EACH SYMBOL INTO A PRETTYPRINTING
ACTION, INDEPENDENTLY OF THE CONTEXT IN WHICH THE SYMBOL
APPEARS. THIS IS ACCOMPLISHED BY A TABLE OF PRETTYPRINTING
OPTIONS.
FOR EACH DISTINGUISHED SYMBOL IN THE TABLE, THERE IS AN
ASSOCIATED SET OF OPTIONS. IF THE OPTION HAS BEEN SELECTED FOR
THE SYMBOL BEING SCANNED, THEN THE ACTION CORRESPONDING WITH
EACH OPTION IS PERFORMED.
THE BASIC ACTIONS INVOLVED IN PRETTYPRINTING ARE THE INDENT-
ATION AND DE-INDENTATION OF THE MARGIN. EACH TIME THE MARGIN IS
INDENTED, THE PREVIOUS VALUE OF THE MARGIN IS PUSHED ONTO A
STACK, ALONG WITH THE NAME OF THE SYMBOL THAT CAUSED IT TO BE
INDENTED. EACH TIME THE MARGIN IS DE-INDENTED, THE STACK IS
POPPED OFF TO OBTAIN THE PREVIOUS VALUE OF THE MARGIN.
THE PRETTYPRINTING OPTIONS ARE PROCESSED IN THE FOLLOWING
ORDER, AND INVOKE THE FOLLOWING ACTIONS:
CRSUPPRESS - IF A CARRIAGE RETURN HAS BEEN INSERTED
FOLLOWING THE PREVIOUS SYMBOL, THEN IT IS
INHIBITED UNTIL THE NEXT SYMBOL IS PRINTED.
CRBEFORE - A CARRIAGE RETURN IS INSERTED BEFORE THE
CURRENT SYMBOL (UNLESS ONE IS ALREADY THERE)
BLANKLINEBEFORE - A BLANK LINE IS INSERTED BEFORE THE CURRENT
SYMBOL (UNLESS ALREADY THERE).
DINDENTONKEYS - IF ANY OF THE SPECIFIED KEYS ARE ON TOP OF
OF THE STACK, THE STACK IS POPPED, DE-INDEN-
TING THE MARGIN. THE PROCESS IS REPEATED
UNTIL THE TOP OF THE STACK IS NOT ONE OF THE
SPECIFIED KEYS.
DINDENT - THE STACK IS UNCONDITIONALLY POPPED AND THE
MARGIN IS DE-INDENTED.
SPACEBEFORE - A SPACE IS INSERTED BEFORE THE SYMBOL BEING
SCANNED (UNLESS ALREADY THERE).
[ THE SYMBOL IS PRINTED AT THIS POINT ]
SPACEAFTER - A SPACE IS INSERTED AFTER THE SYMBOL BEING
SCANNED (UNLESS ALREADY THERE).
GOBBLESYMBOLS - SYMBOLS ARE CONTINUOUSLY SCANNED AND PRINTED
WITHOUT ANY PROCESSING UNTIL ONE OF THE
SPECIFIED SYMBOLS IS SEEN (BUT NOT GOBBLED).
INDENTBYTAB - THE MARGIN IS INDENTED BY A STANDARD AMOUNT
FROM THE PREVIOUS MARGIN.
INDENTTOCLP - THE MARGIN IS INDENTED TO THE CURRENT LINE
POSITION.
CRAFTER - A CARRIAGE RETURN IS INSERTED FOLLOWING THE
SYMBOL SCANNED.
*)
(*Monaco's PASCAL PRETTYPRINTER for UCSD PASCAL
1) To learn how to use the Prettyprinter, see "PRETTY.DOC"
2) Make certain that program to be prettyprinted is in logical unit #5.
3) If you modify the source (PARTA, PARTB, PARTC), you must recompile
PRETTY; note that the $I files are supposed to be on number 5.
4) Object file "PRETTY" should execute on your system as is: no terminal
dependent software is used.
5) The author has found that the prettyprinter works best if the input
to it is left-justified (no leading blanks on any line). I suggest that
you write your PASCAL Program with indentations; then use "REM.BLANKS.CODE"
to get rid of leading blanks and build a file to be input to the
Prettyprinter.
"REM.BLANKS.CODE" expects complete file specifications less ".text" such as
#5:myprog.
6) Lastly, the purpose of prettyprinting is to standardize format for PASCAL
programs to facilitate portability and to increase user familiarity with
the suggested format of Jensen and Wirth. To this end, all programs that you
expect to pass on should be prettyprinted! (NOTE: The prettyprinter is living
proof of this itself). Note: To this end, the prettyprinter transliterates
all lowercase characters not in quoted strings to uppercase and converts all
brackets to (**). ( You can use a single ' inside of a comment )
*)