PROGRAM TITLE: Modula-2 PRETTYPRINTING PROGRAM PROGRAM NAME: PRETTY PROGRAM SUMMARY: This program takes as input a Modula-2 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: a file of characters, presumably a Modula-2 program or program fragment (default extension .MOD). OUTPUT FILE: the prettyprinted program (default extension .NEW). Modula-2 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 80 characters long. Any line longer than this is continued on a separate line. 4. The keywords "UNTIL", "ELSIF", "ELSE" are forced to start on a new line. 5. A blank line is forced before the keywords "MODULE", "PROCEDURE", "CONST", "TYPE", "VAR" and "BEGIN". 6. A space is forced before and after the symbols ":=" and "=". Additionally, a space is forced after the symbols ":". Note that only "="s in declarations are formatted. "="s in expressions are ignored. [ indentation rules ] 1. The bodies of "EXPORT", "IMPORT", "CONST", "TYPE", and "VAR" declarations are indented from their corresponding declaration header keywords. 2. The bodies of "BEGIN-END", "REPEAT", "FOR", "WHILE", "LOOP" "WITH", and "CASE" statements, as well as "RECORD" definitions and "CASE" variants are indented from their header keywords. 3. An "IF-THEN-ELSE" statement is indented as follows: IF expression THEN statement ELSIF expression THEN statement ELSE statement END 4. A "CASE" statement or variant declaration is indented as follows: CASE ... OF labels: statement or decalaration | labels: statement or decalaration | ELSE statement END 5. Any text between the symbol pairs "()", "[]" and "{}" is indented from the opening symbol.