Appendix to Wirth's Pascal Report
This section is an appendix to
the definition of the Pascal language in Niklaus Wirth's
and, with that Report, precisely defines the
This appendix includes a summary of extensions to the language,
gives the ways in which the undefined specifications were resolved,
gives limitations and restrictions of the current implementation,
and lists the added functions and procedures available.
It concludes with a list of differences with the commonly available
Pascal 6000\-3.4 implementation,
and some comments on standard and portable Pascal.
Extensions to the language Pascal
This section defines non-standard language constructs available in
standard Pascal option of the translator
can be used to detect these extensions in programs which are to be transported.
will pad constant strings with blanks in expressions and as
value parameters to make them as long as is required.
\*bvar\fP z : \*bpacked\fP \*barray\fP [ 1 .. 13 ] \*bof\fP char;
The padded blanks are added on the right.
Thus the assignment above is equivalent to:
which is standard Pascal.
Octal constants, octal and hexadecimal write
Octal constants may be given as a sequence of octal digits followed
by the character `b' or `B'.
cause the internal representation of
which must be Boolean, character, integer, pointer, or a user-defined enumerated
to be written in octal or hexadecimal respectively.
expression to be evaluated
each time the statement is executed.
A runtime error results if any of the expressions evaluates to be
statement is treated as a comment if run-time tests are disabled.
Resolution of the undefined specifications
File name \- file variable associations
Each Pascal file variable is associated with a named
exceptions to some of the rules, a name can become associated
with a file in any of three ways:
If a global Pascal file variable appears in the
then it is associated with
If a file was reset or rewritten using the
extended two-argument form of
If a file which has never had
is reset or rewritten without specifying a name
via the second argument, then a temporary name
is associated with the file.
Temporary names start with
`tmp.1' and continue by incrementing the last character in the
Temporary files are removed automatically
when their scope is exited.
\*bprogram\fP <id> ( <file id> { , <file id > } ) ;
The file identifiers (other than
must be declared as variables of
type in the global declaration part.
The files input and output
standard input and output and have a
The following rules must be noted:
contains the formal parameter
is used, explicitly or implicitly, then it must
Unlike all other files, the
must not be defined in a declaration,
as their declaration is automatically:
\*bvar\fP input, output: text
file name has ever been associated with
and no file name is given, then an attempt will be made
If this fails, a run time
calls to output act as for any other file, except that
initially has no associated file.
associates a temporary name with
then reading must be initiated by a call to the
which causes the Pascal system to attempt to open the
If this fails, then a runtime error occurs.
Writing of a file other than
which causes the Pascal system to create the associated
to then open the file for writing only.
is determined by the value of the
If it has its default value 1,
buffered in blocks of up to 512 characters,
flushed whenever a writeln occurs
and at each reference to the file
2 or more gives block buffering without line or
All other output files are always buffered in blocks of 512 characters.
All output buffers are flushed when the files are closed at scope exit,
is called, and can be flushed using the
An important point for an interactive implementation is the definition
is a teletype, and the Pascal system reads a character at the beginning
of execution to define `input\(ua', then no prompt could be printed
by the program before the user is required to type some input.
For this reason, `input\(ua' is not defined by the system until its definition
is needed, reading from a file occurring only when necessary.
is the character set used on
symbols `and', 'or', 'not', '<=', '>=', '<>',
and the uparrow `\(ua' (for pointer qualification)
\*(dgOn many terminals and printers, the up arrow is represented
These are not distinct characters, but rather different graphic
representations of the same internal codes.
Upper and lower case are considered distinct.
composed of all lower case letters.
Thus the identifiers GOTO and GOto are distinct both from each other and
The standard type `boolean' is also available as `Boolean'.
Character strings and constants may be delimited by the character
the latter is sometimes convenient when programs are to be transported.
Note that the `#' character has special meaning
when it is the first character on a line \- see
is conceptually defined as
\*btype\fP integer = minint .. maxint;
is implemented with 32 bit twos complement arithmetic.
Predefined constants of type
\*bconst\fP maxint = 2147483647; minint = -2147483648;
is conceptually defined as
\*btype\fP char = minchar .. maxchar;
Built-in character constants are `minchar' and `maxchar', `bell' and `tab';
ord(minchar) = 0, ord(maxchar) = 127.
is implemented using 64 bit floating point arithmetic.
The floating point arithmetic is done in `rounded' mode, and
provides approximately 17 digits of precision
with numbers as small as 10 to the negative 38th power and as large as
Comments can be delimited by either `{' and `}' or by `(*' and `*)'.
If the character `{' appears in a comment delimited by `{' and `}',
a warning diagnostic is printed.
A similar warning will be printed if the sequence `(*' appears in
a comment delimited by `(*' and `*)'.
The restriction implied by this warning is not part of standard Pascal,
but detects many otherwise subtle errors.
Options of the translator may be controlled
A number of options may appear on the command line invoking the translator.
These options are given as one or more strings of letters preceded by the
character `\-' and cause the default setting of
each given option to be changed.
This method of communication of options is expected to predominate
translates the file foo.p with the listing option enabled (as it normally
is off), and with only standard Pascal features available.
If more control over the portions of the program where options are enabled is
required, then option control in comments can and should be used.
format for option control in comments is identical to that used in Pascal
One places the character `$' as the first character of the comment
and follows it by a comma separated list of directives.
Thus an equivalent to the command line example given above would be:
{$l+,s+ listing on, standard Pascal}
as the first line of the program.
option is more appropriately specified on the command line,
since it is extremely unlikely in an interactive environment
that one wants a listing of the program each time it is translated.
Directives consist of a letter designating the option,
followed either by a `+' to turn the option on, or by a `\-' to turn the
option takes a single digit instead of
The first page of a listing
includes a banner line indicating the version and date of generation of
path name supplied for the source file and the date of
last modification of that file.
Within the body of the listing, lines are numbered consecutively and
correspond to the line numbers for the editor.
kinds of lines may be used to format the listing:
a line consisting of a form-feed
character, control-l, which causes a page
eject in the listing, and a line with
no characters which causes the line number to be suppressed in the listing,
creating a truly blank line.
These lines thus correspond to `eject' and `space' macros found in many
Non-printing characters are printed as the character `?' in the listing.\*(dg
\*(dgThe character generated by a control-i indents
Tab stops are set every 8 columns in
Tabs thus provide a quick way of indenting in the program.
It is also possible to prepare programs whose parts are placed in more
The files other than the main one are called
files and have names ending with `.i'.
The contents of an \*binclude\fR file are referenced through a pseudo-statement
The `#' character must be the first character on the line.
The file name may be delimited with `"' or `\'' characters.
are possible up to 10 deep.
More details are given in sections 5.9 and 5.10.
The standard procedure write
If no minimum field length parameter is specified
string length of the string
The end of each line in a text file should be explicitly
indicated by `writeln(f)', where `writeln(output)' may be written
the built-in function `page(f)' puts a single
form-feed character on the output file.
For programs which are to be transported the filter
can be used to interpret carriage control, as
Restrictions and limitations
Files cannot be members of files or members of dynamically
The calculations involving array subscripts and set elements
are done with 16 bit arithmetic.
restricts the types over which arrays and sets may be defined.
The lower bound of such a range must be greater than or equal to
\-32768, and the upper bound less than 32768.
In particular, strings may have any length from 1 to 32767 characters,
and sets may contain no more than 32767 elements.
There is no intrinsic limit on the length of identifiers.
are considered to be distinct if they differ
in any single position over their entire length.
There is a limit, however, on the maximum input
This is quite generous however, currently exceeding 160
Procedure and function nesting and program size
There is no fundamental, translator defined limit on the size of the
program which can be translated.
The ultimate limit is supplied by the
hardware and the fact that the \s-2PDP\s0-11 has a 16 bit address space.
one runs up against the `ran out of memory' diagnostic the program may yet
translate if smaller procedures are used, as a lot of space is freed
by the translator at the completion of each
There is currently no checking for overflow on arithmetic operations at
Added types, operators, procedures and functions
Additional predefined types
\*btype\fP alfa = \*bpacked\fP \*barray\fP [ 1..10 ] \*bof\fP \*bchar\fP
\*btype\fP intset = \*bset of\fP 0..127
In most cases the context of an expression involving a constant
set allows the translator to determine the type of the set, even though the
constant set itself may not uniquely determine this type.
cases where it is not possible to determine the type of the set from
local context, the expression type defaults to a set over the entire base
type unless the base type is integer\*(dg.
\*(dgThe current translator makes a special case of the construct
`if ... in [ ... ]' and enforces only the more lax restriction
on 16 bit arithmetic given above in this case.
In the latter case the type defaults to the current
which must be ``type set of (a subrange of) integer'' at that point.
\*btype\fP intset = \*bset of\fP 0..58;
then the default integer set is the implicit
Additional predefined operators
The relationals `<' and `>' of proper set
(\*bnot\fR (\fIa\fR < \fIb\fR)) <> (\fIa\fR >= \fIb\fR)
As an example consider the sets
The only relation true between these sets is `<>'.
assigns the (possibly truncated or blank padded)
of the invocation of the current
assigns the current date to the alfa variable
in the format `dd mmm yy ', where `mmm' is the first
three characters of the month, i.e. `Apr'.
writes the output buffered for Pascal file
terminates the execution of the program with
a control flow backtrace.
\*(ddCurrently ignored by
the program to be abnormally terminated if more than
is less than 0 then no limit is imposed.
causes the parameters, which have the format of those
to be written unbuffered on the diagnostic unit 2,
almost always the user's terminal.
a procedure of no arguments which does absolutely nothing.
It is useful as a place holder,
in place of the invisible empty statement.
with trailing blanks eliminated, to be removed.
is a string causes the file whose name
(with blanks trimmed) to be associated with
to the normal function of
is analogous to `reset' above.
is an integer sets the statement limit to be
disables statement limit counting.
causes the current time in the form `\ hh:mm:ss\ ' to be
assigned to the alfa variable
returns the count of arguments when the Pascal program
returns the cardinality of the set
number of elements contained in the set.
returns an integer which is the number of central processor
milliseconds of user time used by this process.
yields the integer valued exponent of the floating-point
expo(\fIx\fP) = entier(log2(abs(\fIx\fP))).
is a real parameter, evaluated but otherwise
ignored, invokes a linear congruential random number generator.
Successive seeds are generated as (seed*a + c) mod m and
the new random number is a normalization of the seed to the range 0.0 to 1.0;
a is 62605, c is 113218009, and m is
is an integer sets the random number generator seed
and returns the previous seed.
has no effect except to yield value
an integer function of no arguments returns the number of central processor
milliseconds of system time used by this process.
Its argument is a real number and
an integer function of no arguments returns the time
in seconds since 00:00:00 GMT January 1, 1970.
Remarks on standard and portable Pascal
It is occasionally desirable to prepare Pascal programs which will be
acceptable at other Pascal installations.
While certain system dependencies are bound to creep in,
judicious design and programming practice can usually eliminate
most of the non-portable usages.
concludes with a standard for implementation and program exchange.
In particular, the following differences may cause trouble when attempting
to transport programs between this implementation and Pascal 6000\-3.4.
translator option may serve to indicate many problem areas.\*(dg
option does not, however, check that identifiers differ
in the first 8 characters.
also does not check the semantics of
Features not available in Berkeley Pascal
Formal parameters which are
Segmented files and associated functions and procedures.
Arrays whose indices exceed the capacity of 16 bit arithmetic.
Features available in Berkeley Pascal but not in Pascal 6000-3.4
with arguments other than character strings.
Sets and strings are more general in \*
see the restrictions given in
for details on the 6000\-3.4 restrictions.
The character set differences may cause problems,
especially the use of the function
characters as arguments to
and comparisons of characters,
since the character set ordering
differs between the two machines.
The Pascal 6000\-3.4 compiler uses a less strict notion of type equivalence.
types are considered identical only if they are represented
by the same type identifier.
Thus, in particular, unnamed types are unique
to the variables/fields declared with them.
Pascal 6000\-3.4 doesn't recognize our option
options to the end of option lists or, better
yet, restrict the option list length to one.
For Pascal 6000\-3.4 the ordering of files in the program statement has
as the first two files in the