PASCAL PROGRAM FORMATTER This document describes certain features of the accompanying portable version of the Pascal program named "pascalformatter". USAGE This program formats Pascal programs according to structured formatting [1, 2] principles, which are documented in the program in comments. The essence of the technique is that each structure is formatted in the simple "inverted-L" form [3], in which all subsequent lines are indented with respect to the first. The program formats program fragments as well as complete programs; a procedure declaration or even just a compound statement is acceptable. Also acceptable is a sequence of program parts, but the label/const/type/var parts must precede the procedure/function parts, which in turn must precede the statement part, and any of these parts may be absent. Thus the program may be used during program development. The only files used are "input" and "output". There are no listing files or error files. If errors are found, these are reported in the output file as comments. If an error comment appears that says "FORMATTING STOPS", then the program has given up its analysis at that point and has copied the remainder of the input to the output without change. The program may modify the statements being processed in one important way: it converts into a compound statement each structured statement that is directly controlled by a structured statement. Such a situation typically occurs every 40 to 60 lines. The modification is necessary to effect a major benefit of the formatting technique, which is that each decrement of indentation (in the statement part) corresponds to the appearance of an "end" or an "until" symbol. This correspondence is very powerful in desk-checking the structure of nested statements. There is one other modification: a semicolon may be inserted before the last "end" of a statement part, for this last "end" always appears on a line by itself. If you wish other "end"s to appear on separate lines, as Gustafson [4] suggests, then you may precede each "end" in the input with a semicolon, or you may modify the formatting program to do this automatically. Please note that, as published, the program uses three spaces for structural indentation and five spaces for continuation indentation. Procedure and function headings are treated as headers for structures, but they are not structures in themselves. They are, however, broken for continuation at each semicolon, rather than at the end of a filled line. You may find the output more pleasing if you place comments after "begin" symbols (as in the Algol 60 style), rather than before, in the input file. The major class of comments that the formatter does not handle well are those within statements. Such comments may be used to give meaning to a numeric code. Perhaps a well-named constant identifier would be more appropriate than a numeric code/comment in such a situation. PORTABILITY The program is written essentially in Standard Pascal, and expects Standard Pascal as input. Certain language dialect features may be passed by default, for the program does only as much syntax analysis as is necessary to recognize the various Pascal structures. The one known non-standard portion of the program is that it uses the ASCII character set. For other character sets, modification of the constants "ordminchar" and "ordmaxchar" will be necessary, as well as modifications to the function "capital" and the procedure "strucconsts". Further, each of the procedures "readline" and "startword" has an "if" statement referring to ASCII control characters; both of these "if" statements can be simply deleted. Another restraint on portability is that it requires a set size of 27 elements. The program does not use set of char. MODIFICATIONS For a specific implementation of Pascal, it may be useful to add to the program a procedure that associates the "input" and "output" with user-named files. If your computer system supports long lines, you may obtain a cleaner format by increasing the values of "maxoutlen" and "alcommbase", with the latter remaining about half of the former. Alternatively, the constants "maxoutlen" and "alcommbase" (at least as used in procedure "copyword") may be changed to variables with user-supplied values. REFERENCES [1] Crider, J. E. "Structured Formatting of Pascal Programs", ACM SIGPLAN Notices, Vol. 13, No. 11 (Nov. 1978), pp. 15-22. [2] Crider, J. E. "Why Use Structured Formatting?", Pascal News, No. 15 (Sept. 1979), pp. 68-70. [3] Bond, R., "Another Note on Pascal Indentation", ACM SIGPLAN Notices, Vol. 14, No. 12 (Dec. 1979), pp. 47-49. [4] Gustafson, G. G., "Some Practical Experiences Formatting Pascal Programs", ACM SIGPLAN Notices, Vol. 14, No. 9 (Sept. 1979), pp. 42-49.