BSD 2 development
[unix-history] / doc / pascal / puman5.n
CommitLineData
1662094b
BJ
1.if \n(xx .bp
2.if !\n(xx \{\
3.so tmac.p \}
4.ND
5.nr H1 4
6.NH
7Details on the components of the system
8.NH 2
9Options
10.PP
11The programs
12.PI
13and
14.XP
15take a number of options.\*(dg
16.FS
17\*(dgAs
18.IX
19uses
20.PI
21to translate Pascal programs,
22it takes the options of
23.PI
24also.
25We refer to them here, however, as
26.PI
27options.
28.FE
29There is a standard
30.UX
31convention for passing options to programs on the command line,
32and this convention is followed by the
33.UP
34system programs.
35As we saw in the examples above,
36option related arguments consisted of the character `\-' followed
37by a single character option name.
38In fact, it is possible to place more than one option letter after
39a single `\-', thus
40.LS
41% \*bpi -lz foo.p\fR
42.LE
43and
44.LS
45% \*bpi -l -z foo.p\fR
46.LE
47are equivalent.
48.PP
49There are 26 options, one corresponding to each lower case letter.
50Except for the
51.B b
52option
53which takes a single digit value,
54each option may be set on (enabled)
55or off (disabled.)
56When an on/off valued option appears on the command line of
57.PI
58or
59.PX
60it inverts the default setting of that option.
61Thus
62.LS
63% \*bpi -l foo.p\fR
64.LE
65enables the listing option
66.B l ,
67since it defaults off, while
68.LS
69% \*bpi -t foo.p\fR
70.LE
71disables the run time tests option
72.B t ,
73since it defaults on.
74.PP
75In additon to inverting the default settings of
76.PI
77options on the command line, it is also possible to control the
78.PI
79options
80within the body of the program by using comments of a special
81form illustrated by
82.LS
83{$l-}
84.LE
85.PP
86Here we see that the opening comment delimiter (which could also be a `(*')
87is immediately followed by the character `$'.
88After this `$', which signals the start of the option list,
89we can place a sequence of letters and option controls, separated by `,'
90characters\*(dd.
91.FS
92\*(ddThis format was chosen because it is used by Pascal 6000-3.4.
93In general the options common to both implementations are controlled
94in the same way so that comment control in options is mostly
95portable.
96It is recommended, however, that only one control be put per comment for
97maximum portability, as the Pascal 6000-3.4
98implementation will ignore controls
99after the first one which it does not recognize.
100.FE
101The most basic actions for options are to set them, thus
102.LS
103{$l+ Enable listing}
104.LE
105or to clear them
106.LS
107{$t-,p- No run-time tests, no post mortem analysis}
108.LE
109Notice that `+' always enables an option and `\-' always disables it,
110no matter what the default is.
111Thus `\-' has a different meaning in an option comment than it has on the
112command line.
113As shown in the examples,
114normal comment text may follow the option list.
115.NH 2
116Pi (and pix)
117.PP
118We now summarize the options of
119.PI .
120These options may also be specified on the command line to
121.IX
122before the name of the file to be translated.
123Arguments to
124.IX
125after the name of the file to be translated are passed to
126the executed program run by
127.X .
128With each option we give its default setting,
129the setting it would have if it appeared on the command line,
130and a sample command using the option.
131Most options are on/off valued,
132with the
133.B b
134option
135taking a single digit value.
136.SH
137Buffering of the file output \- b
138.PP
139The
140.B b
141option controls the buffering of the file
142.I output .
143The default is line buffering, with flushing at
144each reference to the file
145.I input
146and under certain other circumstances detailed in section 5
147below.
148Mentioning
149.B b
150on the command line, e.g.
151.LS
152% \*bpi -b assembler.p\fR
153.LE
154causes standard output to be block buffered,
155where a block is 512 characters.
156The
157.B b
158option may also be controlled in comments.
159It, unique among the
160.UP
161options,
162takes a single digit value rather than an on or off setting.
163A value of 0, e.g.
164.LS
165 {$b0}
166.LE
167causes the file
168.I output
169to be unbuffered.
170Any value 2 or greater causes block buffering and is equivalent
171to the flag on the command line.
172The option control comment setting
173.B b
174must precede the
175.B program
176statement.
177.SH
178Include file listing \- i
179.PP
180The
181.B i
182option takes a list of
183.B include
184files,
185.B procedure
186and
187.B function
188names and causes these portions of the
189program to be listed while translating\*(dg.
190.FS
191\*(dg\*bInclude\fR files are discussed in section 5.9.
192.FE
193All arguments after the
194.B \-i
195flag up to the name of the file being translated,
196which ends in `.p', are in this list.
197Typical uses would be
198.LS
199% \*bpix -i scanner.i compiler.p\fR
200.LE
201to make a listing of the routines in the file scanner.i, and
202.LS
203% \*bpix -i scanner compiler.p\fR
204.LE
205to make a listing of only the routine
206.I scanner .
207This option is especially useful for conservation-minded programmers making
208partial program listings.
209.SH
210Make a listing \- l
211.PP
212The
213.B l
214option enables a listing of the program.
215The
216.B l
217option defaults off.
218When specified on the command line, it causes
219a header line identifying the version of the translator in use
220and a line giving the modification time of the file being translated
221to appear before the actual program listing.
222The
223.B l
224option is pushed and popped by the
225.B i
226option at appropriate points in the program.
227.SH
228Eject new pages for include files \- n
229.PP
230The
231.B n
232option causes
233.PI
234to eject a new page in the listing and print a header line at
235.B include
236file boundaries, providing automatic pagination control.
237To have effect, either the
238.B l
239or
240.B i
241option should also be specified,
242or the input should contain listing control in comments.
243An example would be
244.LS
245% \*bpi -in scan.i c.p\fR
246.LE
247.SH
248Post-mortem dump \- p
249.PP
250The
251.B p
252option defaults on,
253and causes the runtime system to initiate a post-mortem
254backtrace when an error occurs.
255It also cause
256.X
257to count statements in the executing program,
258enforcing a statement limit to prevent infinite loops.
259Specifying
260.B p
261on the command line disables these checks and the ability
262to give this post-mortem analysis.
263It does make smaller and faster programs, however.
264It is also possible to control the
265.B p
266option in comments.
267To prevent the post-mortem backtrace on error,
268.B p
269must be off at the end of the
270.B program
271statement.
272Thus, the Pascal cross-reference program was translated with
273.LS
274% \*bpi -pbt pxref.p\fR
275.LE
276.SH
277Standard Pascal only \- s
278.PP
279The
280.B s
281option causes many of the features of the
282.SM UNIX
283implementation which are not found in standard Pascal
284to be diagnosed as `s' warning errors.
285This option defaults off and is enabled when mentioned on the command line.
286Some of the features which are diagnosed are:
287non-standard
288.B procedure s
289and
290.B function s,
291extensions to the
292.B procedure
293.I write ,
294and the padding of constant strings with blanks.
295In addition, all letters are mapped to lower case except in
296strings and characters so that the case of keywords and identifiers
297is effectively ignored.
298The
299.B s
300option is most useful when a program is to be transported, thus
301.LS
302% \*bpi -s isitstd.p\fR
303.LE
304.SH
305Runtime tests \- t
306.PP
307The
308.B t
309option controls the generation of tests that subrange variable
310values are within bounds at run time.
311By default these tests are generated.
312If the
313.B t
314option is specified on the command line,
315or in a comment which turns it off,
316then the tests are not generated.
317Thus the first line of a program to run without tests might be
318.LS
319{$t- No runtime tests}
320.LE
321Disabling runtime tests also causes
322.B assert
323statements to be treated as comments.\*(dg
324.FS
325\*(dgSee section A.1 for a description of
326.B assert
327statements.
328.FE
329.SH
330Card image, 72 column input \- u
331.PP
332Turning the
333.B u
334option on, either on the command line
335or in a comment causes the input to be treated as
336card images with sequence numbers and truncated to 72 columns.
337Thus
338.LS
339% \*bpix -u cards.p\fR
340.LE
341.SH
342Suppress warning diagnostics \- w
343.PP
344The
345.B w
346option, which defaults on,
347allows the translator to print a number of warnings about inconsistencies
348it finds in the input program.
349Turning this option off with a comment of the form
350.LS
351{$w-}
352.LE
353or on the command line
354.LS
355% \*bpi -w tryme.p\fR
356.LE
357suppresses these usually useful diagnostics.
358.SH
359Generate counters for an execution profile \- z
360.PP
361The
362.B z
363option, which defaults off,
364enables the production of execution profiles.
365By specifying
366.B z
367on the command line, i.e.
368.LS
369% \*bpi -z foo.p\fR
370.LE
371or by enabling it in a comment before the
372.B program
373statement we cause
374.PI
375to insert operations in the interpreter code to
376count the number of times each statement was executed.
377An example of using
378.XP
379was given in section 2.6;
380its options are described in section 5.5.
381.NH 2
382Px
383.PP
384The first argument to
385.X
386is the name of the file containing the program to be interpreted.
387If no arguments are given, then the file
388.I obj
389is executed.
390If more arguments are given, they are available to the Pascal
391program by using the built-ins
392.I argc
393and
394.I argv
395as described in section 4.6.
396.ne 7
397.PP
398.I Px
399may also be invoked automatically.
400In this case, whenever a Pascal object file name is given as a command,
401the command will be executed with
402.X
403prepended to it; that is
404.LS
405% \*bobj primes\fR
406.LE
407will be converted to read
408.LS
409% \*bpx obj primes\fR
410.LE
411.NH 2
412Pxp
413.PP
414.I Pxp
415takes, on its command line, a list of options followed by the program file
416name, which must end in `.p' as it must for
417.PI
418and
419.IX .
420.XP
421will produce an execution profile if any of the
422.B z
423.B t
424or
425.B c
426options are specified on the command line.
427If none of these options are specified, then
428.XP
429functions as a program reformatter.
430See section 5.5 for more details.
431.PP
432It is important to note that only the
433.B z
434option of
435.XP ,
436and the
437.B n ,
438.B u ,
439and
440.B w ,
441options, which are common to
442.PI
443and
444.XP
445can be controlled in comments.
446All other options must be specified on the command line to have any effect.
447.PP
448The following options are relevant to profiling with
449.XP :
450.SH
451Include the bodies of all routines in the profile \- a
452.PP
453.I Pxp
454normally suppresses printing the bodies of routines
455which were never executed, to make the profile more compact.
456This option forces all routine bodies to be printed.
457.SH
458Extract profile data from the file core \- c
459.PP
460This option causes
461.XP
462to extract the data from the file
463.I core
464in the current directory.
465This is used in debugging the Pascal system, and should not
466normally be needed.
467When an abnormal termination occurs in
468.X
469it writes the data to the file
470.I pmon.out .
471The
472.B z
473option enables profiling with data from this file.
474.SH
475Suppress declaration parts from a profile \- d
476.PP
477Normally a profile includes declaration parts.
478Specifying
479.B d
480on the command line suppresses declaration parts.
481.SH
482Eliminate include directives \- e
483.PP
484Normally,
485.XP
486preserves
487.B include
488directives to the output when reformatting a program,
489as though they were comments.
490Specifying
491.B \-e
492causes the contents of the specified files to be reformatted
493into the output stream instead.
494This is an easy way to eliminate
495.B include
496directives, e.g. before transporting a program.
497.SH
498Fully parenthesize expressions \- f
499.PP
500Normally
501.XP
502prints expressions with the minimal parenthesization necessary to
503preserve the structure of the input.
504This option causes
505.I pxp
506to fully parenthesize expressions.
507Thus the statement which prints as
508.LS
509d := a + b mod c / e
510.LE
511with minimal parenthesization, the default, will print as
512.LS
513d := a + ((b mod c) / e)
514.LE
515with the
516.B f
517option specified on the command line.
518.SH
519Left justify all procedures and functions \- j
520.PP
521Normally, each
522.B procedure
523and
524.B function
525body is indented to reflect its static nesting depth.
526This option prevents this nesting and can be used if the indented
527output would be too wide.
528.SH
529Print a table summarizing procedure and function calls \- t
530.PP
531The
532.B t
533option causes
534.XP
535to print a table summarizing the number of calls to each
536.B procedure
537and
538.B function
539in the program.
540It may be specified in combination with the
541.B z
542option, or separately.
543.SH
544Enable and control the profile \- z
545.PP
546The
547.B z
548profile option is very similar to the
549.B i
550listing control option of
551.PI .
552If
553.B z
554is specified on the command line, then all arguments up to the
555source file argument which ends in `.p' are taken to be the names of
556.B procedure s
557and
558.B function s
559or
560.B include
561files which are to be profiled.
562If this list is null, then the whole file is to be profiled.
563A typical command for extracting a profile of part of a large program
564would be
565.LS
566% \*bpxp -z test parser.i compiler.p\fR
567.LE
568This specifies that profiles of the routines in the file
569.I parser.i
570and the routine
571.I test
572are to be made.
573.NH 2
574Formatting programs using pxp
575.PP
576The program
577.XP
578can be used to reformat programs, by using a command of the form
579.LS
580% \*bpxp dirty.p > clean.p\fR
581.LE
582Note that since the shell creates the output file `clean.p' before
583.XP
584executes, so `clean.p' and `dirty.p' must not be the same file.
585.PP
586.I Pxp
587automatically paragraphs the program, performing housekeeping
588chores such as comment alignment, and
589treating blank lines, lines containing exactly one blank
590and lines containing only a form-feed character as though they
591were comments, preserving their vertical spacing effect in the output.
592.I Pxp
593distinguishes between four kinds of comments:
594.HP
595.RS
596.IP 1)
597Left marginal comments, which begin in the first column of the
598input line and are placed in the first column of an output line.
599.IP 2)
600Aligned comments, which are preceded by no input tokens on the
601input line.
602These are aligned in the output with the running program text.
603.IP 3)
604Trailing comments, which are preceded in the input line by a token with
605no more than two spaces separating the token from the comment.
606.IP 4)
607Right marginal comments, which are preceded in the input line
608by a token from which they are separated by at least three spaces or a tab.
609These are aligned down the right margin of the output,
610currently to the first tab stop after the 40th column from the current
611``left margin''.
612.RE
613.LP
614Consider the following program.
615.LS
616% \*bcat comments.p\fR
617.so comments1.p
618.LE
619When formatted by
620.XP
621the following output is produced.
622.LS
623% \*bpxp comments.p\fR
624.so commentsout
625%
626.LE
627The following formatting related options are currently available in
628.XP .
629The options
630.B f
631and
632.B j
633described in the previous section may also be of interest.
634.SH
635Strip comments \-s
636.PP
637The
638.B s
639option causes
640.XP
641to remove all comments from the input text.
642.SH
643Underline keywords \- \_
644.PP
645A command line argument of the form
646.B \-\_
647as in
648.LS
649% \*bpxp -_ dirty.p\fR
650.LE
651can be used to cause
652.XP
653to underline all keywords in the output for enhanced readability.
654.SH
655Specify indenting unit \- [23456789]
656.PP
657The normal unit which
658.XP
659uses to indent a structure statement level is 4 spaces.
660By giving an argument of the form
661\fB\-\fId\fR
662with
663.I d
664a digit,
6652 \(<=
666.I d
667\(<= 9
668you can specify that
669.I d
670spaces are to be used per level instead.
671.NH 2
672Pcc and carriage control
673.PP
674The
675.UX
676system printer driver does not implement
677.SM FORTRAN
678style carriage control.
679Thus the function
680.I page
681on
682.UX
683does not output a character `1'
684in column 1 of a line, but rather puts out a form-feed
685character.
686For those who wish to use carriage control, the filter
687.I pcc
688is available which interprets this control.
689A sample usage is:
690.LS
691% \*bpx | pcc\fR
692.LE
693or
694.LS
695% \*bpix prog.p | pcc | lpr\fR
696.LE
697for printer copy.
698.I Pcc
699is fully described by its manual documentation
700.I pcc
701(6).
702.NH 2
703Pxref
704.PP
705The cross-reference program
706.I pxref
707may be used to make cross-referenced listings of Pascal
708programs.
709To produce a cross-reference of the program in the file
710`foo.p'
711one can execute the command:
712.LS
713% \*bpxref foo.p\fR
714.LE
715The cross-reference is, unfortunately, not block structured.
716Full details on
717.I pxref
718are given in its manual section
719.I pxref
720(6).
721.NH 2
722Pascals
723.PP
724A version of Wirth's subset Pascal translator
725.I pascals
726is available on
727.UX .
728It was translated to interpreter code by
729.PI
730and is invoked by a command of the form:
731.LS
732% \*bpascals prog.p\fR
733.LE
734The program in the file given is translated to interpretive code
735which is then immediately executed.
736.I Pascals
737is thus similar to
738.I pix .
739Only small programs can be handled.
740.I Pascals
741is most interesting to those wishing to study its error recovery techniques,
742which are described in Wirth's book
743.I "Algorithms + Data Structures = Programs" .
744.NH 2
745Multi-file programs
746.PP
747A text inclusion facility is available with
748.UP .
749This facility allows the interpolation of source text from other
750files into the source stream of the translator.
751It can be used to divide large programs into more manageable pieces
752for ease in editing, listing, and maintenance.
753.PP
754The
755.B include
756facility is based on that of the
757.SM
758UNIX
759.NL
760C compiler.
761To trigger it you can place the character `#' in the first portion of
762a line and then, after an arbitrary number of blanks or tabs,
763the word
764`include'
765followed by a filename enclosed in single `\(aa' or double `"' quotation
766marks.
767The file name may be followed by a semicolon `;' if you wish to treat
768this as a pseudo-Pascal statement.
769The filenames of included files must end in `.i'.
770An example of the use of included files in a main program would be:
771.LS
772\*bprogram\fR compiler(input, output, obj);
773
774#\*binclude\fR "globals.i"
775#\*binclude\fR "scanner.i"
776#\*binclude\fR "parser.i"
777#\*binclude\fR "semantics.i"
778
779\*bbegin\fR
780 { main program }
781\*bend\fR.
782.LE
783.PP
784At the point the
785.B include
786pseudo-statement is encountered in the input, the lines from
787the included file are interpolated into the input stream.
788For the purposes of translate- and run-time diagnostics and
789statement numbers in the listings and post-mortem backtraces,
790the lines in the included file are numbered from 1.
791Nested includes are possible up to 10 deep.
792.PP
793See the descriptions of the
794.B i
795and
796.B n
797options of
798.PI
799in section 5.2
800above;
801these can be used to control listing when
802.B include
803files are present.
804.PP
805.I Include
806control lines are never printed in a listing.
807If the
808.B n
809option is not set, they are replaced by a line containing
810the file name and a `:' character.
811This is the default setting.
812If the
813.B n
814new page option is enabled then the
815.B include
816line is replaced with a banner line similar to the first line
817of a listing.
818This line is placed on a new page in the listing.
819.PP
820When a non-trivial line is encountered in the source text after an
821.B include
822finishes, the
823`popped' filename is printed, in the same manner as above.
824.PP
825For the purposes of error diagnostics when not making a listing, the filename
826will be printed before each diagnostic if the current
827filename has changed since the last
828filename was printed.