BSD 4_3_Net_2 release
[unix-history] / usr / src / share / doc / ps1 / 04.pascal / puman5.n
CommitLineData
3edcb7c8
KB
1.\" Copyright (c) 1980 The Regents of the University of California.
2.\" All rights reserved.
1c451c0a 3.\"
af359dea
C
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
3edcb7c8 19.\"
af359dea
C
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" @(#)puman5.n 6.3 (Berkeley) 4/17/91
1c451c0a 33.\"
1c451c0a
KM
34.if !\n(xx \{\
35.so tmac.p \}
36.ND
37.nr H1 4
38.NH
39Details on the components of the system
40.NH 2
41Options
42.PP
43The programs
44.PI ,
45.PC ,
46and
47.XP
48take a number of options.\*(dg
49.FS
50\*(dgAs
51.IX
52uses
53.PI
54to translate Pascal programs,
55it takes the options of
56.PI
57also.
58We refer to them here, however, as
59.PI
60options.
61.FE
62There is a standard
63.UX
64convention for passing options to programs on the command line,
65and this convention is followed by the
66.UP
67system programs.
68As we saw in the examples above,
69option related arguments consisted of the character `\-' followed
70by a single character option name.
71.PP
72Except for the
73.B b
74option
75which takes a single digit value,
76each option may be set on (enabled)
77or off (disabled.)
78When an on/off valued option appears on the command line of
79.PI
80or
81.PX
82it inverts the default setting of that option.
83Thus
84.LS
85% \*bpi -l foo.p\fR
86.LE
87enables the listing option
88.B l ,
89since it defaults off, while
90.LS
91% \*bpi -t foo.p\fR
92.LE
93disables the run time tests option
94.B t ,
95since it defaults on.
96.PP
97In additon to inverting the default settings of
98.PI
99options on the command line, it is also possible to control the
100.PI
101options
102within the body of the program by using comments of a special
103form illustrated by
104.LS
105{$l-}
106.LE
107.PP
108Here we see that the opening comment delimiter (which could also be a `(*')
109is immediately followed by the character `$'.
110After this `$', which signals the start of the option list,
111we can place a sequence of letters and option controls, separated by `,'
112characters\*(dd.
113.FS
114\*(ddThis format was chosen because it is used by Pascal 6000-3.4.
115In general the options common to both implementations are controlled
116in the same way so that comment control in options is mostly
117portable.
118It is recommended, however, that only one control be put per comment for
119maximum portability, as the Pascal 6000-3.4
120implementation will ignore controls
121after the first one which it does not recognize.
122.FE
123The most basic actions for options are to set them, thus
124.LS
125{$l+ Enable listing}
126.LE
127or to clear them
128.LS
129{$t-,p- No run-time tests, no post mortem analysis}
130.LE
131Notice that `+' always enables an option and `\-' always disables it,
132no matter what the default is.
133Thus `\-' has a different meaning in an option comment than it has on the
134command line.
135As shown in the examples,
136normal comment text may follow the option list.
137.NH 2
138Options common to Pi, Pc, and Pix
139.PP
140The following options are common to both the compiler
141and the interpreter.
142With each option we give its default setting,
143the setting it would have if it appeared on the command line,
144and a sample command using the option.
145Most options are on/off valued,
146with the
147.B b
148option
149taking a single digit value.
150.SH
151Buffering of the file output \- b
152.PP
153The
154.B b
155option controls the buffering of the file
156.I output .
157The default is line buffering, with flushing at
158each reference to the file
159.I input
160and under certain other circumstances detailed in section 5
161below.
162Mentioning
163.B b
164on the command line, e.g.
165.LS
166% \*bpi -b assembler.p\fR
167.LE
168causes standard output to be block buffered,
169where a block is some system\-defined number of characters.
170The
171.B b
172option may also be controlled in comments.
173It, unique among the
174.UP
175options,
176takes a single digit value rather than an on or off setting.
177A value of 0, e.g.
178.LS
179 {$b0}
180.LE
181causes the file
182.I output
183to be unbuffered.
184Any value 2 or greater causes block buffering and is equivalent
185to the flag on the command line.
186The option control comment setting
187.B b
188must precede the
189.B program
190statement.
191.SH
192Include file listing \- i
193.PP
194The
195.B i
196option takes the name of an
197.B include
198file,
199.B procedure
200or
201.B function
202name and causes it
203to be listed while translating\*(dg.
204.FS
205\*(dg\*bInclude\fR files are discussed in section 5.9.
206.FE
207Typical uses would be
208.LS
209% \*bpix -i scanner.i compiler.p\fR
210.LE
211to make a listing of the routines in the file scanner.i, and
212.LS
213% \*bpix -i scanner compiler.p\fR
214.LE
215to make a listing of only the routine
216.I scanner .
217This option is especially useful for conservation-minded programmers making
218partial program listings.
219.SH
220Make a listing \- l
221.PP
222The
223.B l
224option enables a listing of the program.
225The
226.B l
227option defaults off.
228When specified on the command line, it causes
229a header line identifying the version of the translator in use
230and a line giving the modification time of the file being translated
231to appear before the actual program listing.
232The
233.B l
234option is pushed and popped by the
235.B i
236option at appropriate points in the program.
237.SH
238Standard Pascal only \- s
239.PP
240The
241.B s
242option causes many of the features of the
243.SM UNIX
244implementation which are not found in standard Pascal
245to be diagnosed as `s' warning errors.
246This option defaults off and is enabled when mentioned on the command line.
247Some of the features which are diagnosed are:
248non-standard
249.B procedure s
250and
251.B function s,
252extensions to the
253.B procedure
254.I write ,
255and the padding of constant strings with blanks.
256In addition, all letters are mapped to lower case except in
257strings and characters so that the case of keywords and identifiers
258is effectively ignored.
259The
260.B s
261option is most useful when a program is to be transported, thus
262.LS
263% \*bpi -s isitstd.p\fR
264.LE
265will produce warnings unless the program meets the standard.
266.SH
267Runtime tests \- t and C
268.PP
269These
270options control the generation of tests that subrange variable
271values are within bounds at run time.
272.PI
273defaults to generating tests and uses the option
274.B t
275to disable them.
276.PC
277defaults to not generating tests,
278and uses the option
279.B C
280to enable them.
281Disabling runtime tests also causes
282.B assert
283statements to be treated as comments.\*(dd
284.FS
285\*(ddSee section A.1 for a description of
286.B assert
287statements.
288.FE
289.SH
290Suppress warning diagnostics \- w
291.PP
292The
293.B w
294option, which defaults on,
295allows the translator to print a number of warnings about inconsistencies
296it finds in the input program.
297Turning this option off with a comment of the form
298.LS
299{$w-}
300.LE
301or on the command line
302.LS
303% \*bpi -w tryme.p\fR
304.LE
305suppresses these usually useful diagnostics.
306.SH
307Generate counters for a pxp execution profile \- z
308.PP
309The
310.B z
311option, which defaults off,
312enables the production of execution profiles.
313By specifying
314.B z
315on the command line, i.e.
316.LS
317% \*bpi -z foo.p\fR
318.LE
319or by enabling it in a comment before the
320.B program
321statement causes
322.PI
323and
324.PC
325to insert operations in the interpreter code to
326count the number of times each statement was executed.
327An example of using
328.XP
329was given in section 2.6;
330its options are described in section 5.6.
331Note that the
332.B z
333option cannot be used on separately compiled programs.
334.NH 2
335Options available in Pi
336.SH
337Post-mortem dump \- p
338.PP
339The
340.B p
341option defaults on,
342and causes the runtime system to initiate a post-mortem
343backtrace when an error occurs.
344It also cause
345.X
346to count statements in the executing program,
347enforcing a statement limit to prevent infinite loops.
348Specifying
349.B p
350on the command line disables these checks and the ability
351to give this post-mortem analysis.
352It does make smaller and faster programs, however.
353It is also possible to control the
354.B p
355option in comments.
356To prevent the post-mortem backtrace on error,
357.B p
358must be off at the end of the
359.B program
360statement.
361Thus, the Pascal cross-reference program was translated with
362.LS
363% \*bpi -pbt pxref.p\fR
364.LE
365.NH 2
366Options available in Px
367.PP
368The first argument to
369.X
370is the name of the file containing the program to be interpreted.
371If no arguments are given, then the file
372.I obj
373is executed.
374If more arguments are given, they are available to the Pascal
375program by using the built-ins
376.I argc
377and
378.I argv
379as described in section 4.6.
380.ne 7
381.PP
382.I Px
383may also be invoked automatically.
384In this case, whenever a Pascal object file name is given as a command,
385the command will be executed with
386.X
387prepended to it; that is
388.LS
389% \*bobj primes\fR
390.LE
391will be converted to read
392.LS
393% \*bpx obj primes\fR
394.LE
395.NH 2
396Options available in Pc
397.SH
398Generate assembly language \- S
399.PP
400The program is compiled and the assembly language
401output is left in file appended .s.
402Thus
403.LS
404% \*bpc -S foo.p\fR
405.LE
406creates a file
407.I foo.s .
408No executable file is created.
409.SH
410Symbolic Debugger Information \- g
411.PP
412The
413.B g
414option causes the compiler to generate information
415needed by
416.I sdb (1)
417the symbolic debugger.
418For a complete description of
419.I sdb
420see Volume 2c of the
421.UX
422Reference Manual.
423.SH
424Redirect the output file \- o
425.PP
426The
427.I name
428argument after the
429.B -o
430is used as the name of the output file instead of
431.I a.out .
432Its typical use is to name the compiled program using
433the root of the file name.
434Thus:
435.LS
436% \*bpc -o myprog myprog.p\fR
437.LE
438causes the compiled program to be called
439.I myprog .
440.SH
441Generate counters for a \*iprof\fP execution profile \- p
442.PP
443The compiler produces code which counts the number of times each
444routine is called.
445The profiling is based on a periodic sample taken by the
446system rather than by inline counters used by
447.XP .
448This results in less degradation in execution,
449at somewhat of a loss in accuracy.
450See
451.I prof (1)
452for a more complete description.
453.SH
454Run the object code optimizer \- O
455.PP
456The output of the compiler is run through
457the object code optimizer.
458This provides an increase in compile time in
459exchange for a decrease in compiled code size
460and execution time.
461.NH 2
462Options available in Pxp
463.PP
464.I Pxp
465takes, on its command line, a list of options followed by the program file
466name, which must end in `.p' as it must for
467.PI ,
468.PC ,
469and
470.IX .
471.I Pxp
472will produce an execution profile if any of the
473.B z ,
474.B t
475or
476.B c
477options is specified on the command line.
478If none of these options is specified, then
479.XP
480functions as a program reformatter.
481.PP
482It is important to note that only the
483.B z
484and
485.B w
486options of
487.XP ,
488which are common to
489.PI ,
490.PC ,
491and
492.XP
493can be controlled in comments.
494All other options must be specified on the command line to have any effect.
495.PP
496The following options are relevant to profiling with
497.XP :
498.SH
499Include the bodies of all routines in the profile \- a
500.PP
501.I Pxp
502normally suppresses printing the bodies of routines
503which were never executed, to make the profile more compact.
504This option forces all routine bodies to be printed.
505.SH
506Suppress declaration parts from a profile \- d
507.PP
508Normally a profile includes declaration parts.
509Specifying
510.B d
511on the command line suppresses declaration parts.
512.SH
513Eliminate include directives \- e
514.PP
515Normally,
516.XP
517preserves
518.B include
519directives to the output when reformatting a program,
520as though they were comments.
521Specifying
522.B \-e
523causes the contents of the specified files to be reformatted
524into the output stream instead.
525This is an easy way to eliminate
526.B include
527directives, e.g. before transporting a program.
528.SH
529Fully parenthesize expressions \- f
530.PP
531Normally
532.XP
533prints expressions with the minimal parenthesization necessary to
534preserve the structure of the input.
535This option causes
536.I pxp
537to fully parenthesize expressions.
538Thus the statement which prints as
539.LS
540d := a + b mod c / e
541.LE
542with minimal parenthesization, the default, will print as
543.LS
544d := a + ((b mod c) / e)
545.LE
546with the
547.B f
548option specified on the command line.
549.SH
550Left justify all procedures and functions \- j
551.PP
552Normally, each
553.B procedure
554and
555.B function
556body is indented to reflect its static nesting depth.
557This option prevents this nesting and can be used if the indented
558output would be too wide.
559.SH
560Print a table summarizing procedure and function calls \- t
561.PP
562The
563.B t
564option causes
565.XP
566to print a table summarizing the number of calls to each
567.B procedure
568and
569.B function
570in the program.
571It may be specified in combination with the
572.B z
573option, or separately.
574.SH
575Enable and control the profile \- z
576.PP
577The
578.B z
579profile option is very similar to the
580.B i
581listing control option of
582.PI .
583If
584.B z
585is specified on the command line, then all arguments up to the
586source file argument which ends in `.p' are taken to be the names of
587.B procedure s
588and
589.B function s
590or
591.B include
592files which are to be profiled.
593If this list is null, then the whole file is to be profiled.
594A typical command for extracting a profile of part of a large program
595would be
596.LS
597% \*bpxp -z test parser.i compiler.p\fR
598.LE
599This specifies that profiles of the routines in the file
600.I parser.i
601and the routine
602.I test
603are to be made.
604.NH 2
605Formatting programs using pxp
606.PP
607The program
608.XP
609can be used to reformat programs, by using a command of the form
610.LS
611% \*bpxp dirty.p > clean.p\fR
612.LE
613Note that since the shell creates the output file `clean.p' before
614.XP
615executes, so `clean.p' and `dirty.p' must not be the same file.
616.PP
617.I Pxp
618automatically paragraphs the program, performing housekeeping
619chores such as comment alignment, and
620treating blank lines, lines containing exactly one blank
621and lines containing only a form-feed character as though they
622were comments, preserving their vertical spacing effect in the output.
623.I Pxp
624distinguishes between four kinds of comments:
625.HP
626.RS
627.IP 1)
628Left marginal comments, which begin in the first column of the
629input line and are placed in the first column of an output line.
630.IP 2)
631Aligned comments, which are preceded by no input tokens on the
632input line.
633These are aligned in the output with the running program text.
634.IP 3)
635Trailing comments, which are preceded in the input line by a token with
636no more than two spaces separating the token from the comment.
637.IP 4)
638Right marginal comments, which are preceded in the input line
639by a token from which they are separated by at least three spaces or a tab.
640These are aligned down the right margin of the output,
641currently to the first tab stop after the 40th column from the current
642``left margin''.
643.RE
644.LP
645Consider the following program.
646.LS
647% \*bcat comments.p\fR
648.so comments1.p
649.LE
650When formatted by
651.XP
652the following output is produced.
653.LS
654% \*bpxp comments.p\fR
655.so commentsout
656%
657.LE
658The following formatting related options are currently available in
659.XP .
660The options
661.B f
662and
663.B j
664described in the previous section may also be of interest.
665.SH
666Strip comments \-s
667.PP
668The
669.B s
670option causes
671.XP
672to remove all comments from the input text.
673.SH
674Underline keywords \- \_
675.PP
676A command line argument of the form
677.B \-\_
678as in
679.LS
680% \*bpxp -_ dirty.p\fR
681.LE
682can be used to cause
683.XP
684to underline all keywords in the output for enhanced readability.
685.SH
686Specify indenting unit \- [23456789]
687.PP
688The normal unit which
689.XP
690uses to indent a structure statement level is 4 spaces.
691By giving an argument of the form
692\fB\-\fId\fR
693with
694.I d
695a digit,
6962 \(<=
697.I d
698\(<= 9
699you can specify that
700.I d
701spaces are to be used per level instead.
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(1).
721.NH 2
722Multi-file programs
723.PP
724A text inclusion facility is available with
725.UP .
726This facility allows the interpolation of source text from other
727files into the source stream of the translator.
728It can be used to divide large programs into more manageable pieces
729for ease in editing, listing, and maintenance.
730.PP
731The
732.B include
733facility is based on that of the
734.SM
735UNIX
736.NL
737C compiler.
738To trigger it you can place the character `#' in the first portion of
739a line and then, after an arbitrary number of blanks or tabs,
740the word
741`include'
742followed by a filename enclosed in single `\(aa' or double `"' quotation
743marks.
744The file name may be followed by a semicolon `;' if you wish to treat
745this as a pseudo-Pascal statement.
746The filenames of included files must end in `.i'.
747An example of the use of included files in a main program would be:
748.LS
749\*bprogram\fR compiler(input, output, obj);
750
751#\*binclude\fR "globals.i"
752#\*binclude\fR "scanner.i"
753#\*binclude\fR "parser.i"
754#\*binclude\fR "semantics.i"
755
756\*bbegin\fR
757 { main program }
758\*bend\fR.
759.LE
760.PP
761At the point the
762.B include
763pseudo-statement is encountered in the input, the lines from
764the included file are interpolated into the input stream.
765For the purposes of translation and runtime diagnostics and
766statement numbers in the listings and post-mortem backtraces,
767the lines in the included file are numbered from 1.
768Nested includes are possible up to 10 deep.
769.PP
770See the descriptions of the
771.B i
772option of
773.PI
774in section 5.2
775above;
776this can be used to control listing when
777.B include
778files are present.
779.PP
780When a non-trivial line is encountered in the source text after an
781.B include
782finishes, the
783`popped' filename is printed, in the same manner as above.
784.PP
785For the purposes of error diagnostics when not making a listing, the filename
786will be printed before each diagnostic if the current
787filename has changed since the last
788filename was printed.
789.NH 2
790Separate Compilation with Pc
791.PP
792A separate compilation facility is provided with the Berkeley Pascal compiler,
793.PC .
794This facility allows programs to be divided into a number of files and
795the pieces to be compiled individually,
796to be linked together at some later time.
797This is especially useful for large programs,
798where small changes would otherwise require
799time-consuming re-compilation of the entire program.
800.PP
801Normally,
802.PC
803expects to be given entire Pascal programs.
804However, if given the
805.B \-c
806option on the command line, it will accept a sequence of definitions and
807declarations, and compile them into a
808.B .o
809file, to be linked with a Pascal program at a later time.
810In order that procedures and functions be available across
811separately compiled files, they must be declared with the directive
812.B external .
813This directive is similar to the directive
814.B forward
815in that it must precede the resolution of the function or procedure,
816and formal parameters and function result types must be specified
817at the
818.B external
819declaration and may not be specified at the resolution.
820.PP
821Type checking is performed across separately compiled files.
822Since Pascal type defintions define unique types,
823any types which are shared between separately compiled files
824must be the same definition.
825This seemingly impossible problem is solved using a facility similar
826to the
827.B include
828facility discussed above.
829Definitions may be placed in files with the extension
830.B .h
831and the files included by separately compiled files.
832Each definition from a
833.B .h
834file defines a unique type, and all uses of a definition from the same
835.B .h
836file define the same type.
837Similarly, the facility is extended to allow the definition of
838.B const s
839and the declaration of
840.B label s,
841.B var s,
842and
843.B external
844.B function s
845and
846.B procedure s.
847Thus
848.B procedure s
849and
850.B function s
851which are used between separately compiled files must be declared
852.B external ,
853and must be so declared in a
854.B .h
855file included by any file which calls or resolves the
856.B function
857or
858.B procedure .
859Conversely,
860.B function s
861and
862.B procedure s
863declared
864.B external
865may only be so declared in
866.B .h
867files.
868These files may be included only at the outermost level,
869and thus define or declare global objects.
870Note that since only
871.B external
872.B function
873and
874.B procedure
875declarations (and not resolutions) are allowed in
876.B .h
877files, statically nested
878.B function s
879and
880.B procedure s
881can not be declared
882.B external .
883.PP
884An example of the use of included
885.B .h
886files in a program would be:
887.LS
888\*bprogram\fR compiler(input, output, obj);
889
890#\*binclude\fR "globals.h"
891#\*binclude\fR "scanner.h"
892#\*binclude\fR "parser.h"
893#\*binclude\fR "semantics.h"
894
895\*bbegin\fR
896 { main program }
897\*bend\fR.
898.LE
899.PP
900This might include in the main program
901the definitions and declarations of all the global
902.B label s,
903.B const s,
904.B type s and
905.B var s
906from the file globals.h,
907and the
908.B external
909.B function
910and
911.B procedure
912declarations for each of the
913separately compiled files for the scanner, parser and semantics.
914The header file
915.I scanner.h
916would contain declarations of the form:
917.LS
918\*btype\fR
919 token = \*brecord\fR
920 { token fields }
921 \*bend\fR;
922
923\*bfunction\fR scan(\*bvar\fR inputfile: text): token;
924 \*bexternal\fR;
925.LE
926.ne 15
927Then the scanner might be in a separately compiled file containing:
928.LS
929#\*binclude\fR "globals.h"
930#\*binclude\fR "scanner.h"
931
932\*bfunction\fR scan;
933\*bbegin\fR
934 { scanner code }
935\*bend\fR;
936.LE
937which includes the same global definitions and declarations
938and resolves the scanner functions and procedures declared
939.B external
940in the file scanner.h.