Pascal-P: The portable Pascal compiler


Niklaus Wirth's team in Zurich produced two compilers for the original language Pascal. One was the CDC 6000 series compiler, which is documented here. The other was the Pascal-P compiler/interpreter. The difference was the CDC 6000 compiler produced object code for the CDC 6000 computers in a single step, single pass compiler, and was thus tied to that machine. The Pascal-P compiler was specifically designed to be portable to many machines, and to enable the creation of new Pascal implementations.

The trade off was that Pascal-P didn't generate object code for any real machine, but rather interpreted the output code. In addition, it was designed to both compile a subset of the full Pascal language, and also be written exclusively in that subset. The reason for the latter was primarily that the machines available in the 1970's were memory limited, and bootstrapping a new compiler, which often involved generating and using non-optimal code, required a lot of memory. Having a compiler that only processed a subset of the language allowed it to be bootstrapped on a memory limited machine, then brought up to full compliance after it was running.

Unfortunately, this also created a defacto language consisting of the Pascal-P subset of Pascal. Many implementers never added back the full Pascal language to their implementations, and the lack of an example of how to implement advanced features of Pascal in Pascal-P didn't help. The Pascal-P "language" persists today. Borland/Delphi retained most of the Pascal-P limitations because it started out based on the UCSD system (abet loosely).

Pascal-P occupies a special place here because, unlike the CDC 6000 compiler, it can be compiled and run on available machines today. Whereas the CDC 6000 compiler has only a past, the Pascal-P compiler/interpreter has a past, a present, and increasingly, a future.


History


In the early part of this century, many of the original Pascal sources became available, from early version of Pascal-P, to the original CDC compilers. Although the literature hints at it, the actual source makes it clear. The second CDC compiler, using the revised Pascal language, and the existing copy of Pascal-P2 are clearly from the same codebase. Since the vast majority of the early Pascal compilers were based on either the Pascal-P compiler or the CDC compiler, this means that many, perhaps even most compilers were based on the original copy of Pascal-P.

As chronicled in "The Zurich implementation", the first version of a Pascal compiler was done in Scallop, a language specific to the CDC series. This followed an unsucessful implementation in Fortran. It was unsucessful because Fortran had difficulty processing the recursive structures of Pascal.

The Scallop compiler was actually written in Pascal, but without a compiler to translate it. Instead, the source for the compiler was hand-translated to Scallop from unrevised Pascal to create a working compiler. Then the compiler was used to compile itself. This "bootstrapping" method was used to create the 1972 unrevised language compiler on the CDC page here.

The language the first compiler processed is very different from the Pascal that appears today. There was no program header, pointers were referred to as "classes" (apparently because pointers can reference a "class" of variables), and other differences. This is the language of the 1970 Pascal User Manual.

In the summer of 1972, a new compiler was started that used the "revised" Pascal language, or the form of Pascal that survives today as ISO 7185 Pascal. The compiler was designed to be portable, and the first target machine of the compiler was a "Stack computer" or pseudo-machine to execute code using an interpreter (a technique that was popularized in the language BCPL, the ancestor of C). This was the first version of Pascal-P.

After that, or perhaps at the same time, a Pascal-P was modified in a branch to become the 1974 CDC series compiler. The main difference between the two was that Pascal-P was presented as a separate compiler and interpreter, whereas the CDC compiler used the compiler front end modified to directly generate code for the CDC series computers. The other difference is that the CDC compiler was enhanced to process the full language of Pascal, not a subset.

In 1974 Niklaus Wirth made an effort with his students to collect the versions of Pascal-P that had propagated around Zurich, and come up with a single, comprehensive Pascal porting kit based on Pascal-P. This was termed Pascal-P2. What happened to Pascal-P1? Probally the only living example of it is the 1974 CDC compiler, which came out around the same time.

The final version or versions of Pascal-P from Zurich were the twin P3 and P4 compilers released in 1976. There were created at the same time, but P3 was designed to be backwards compatible with P2. This was to aid anyone who had a serious investment in P2, such as their own backend. P4 was redesigned such as to be better, and incompatible with P2. Only P4 survives to this day.

From 1976, nothing happened at Zurich until the ISO 7185 standard was released in 1982. Outside Zurich, plenty of things were happening. Kenneth bowles used the P2 system to create UCSD Pascal, which in turn became the prototype for Borland Turbo Pascal. The DEC PDP-10 compiler was derived from both the Pascal-P2 and CDC compilers. And many other implementations followed. In 1977 the working group for ISO 7185 Pascal was formed.

In 1982, the ISO 7185 standard was issued.

Timeline

Year

Event

1970-1971

Niklaus Wirth defines the first version of the language Pascal, the first version of the CDC 6000 compiler is created

1972-1974 

Work on the second version of the language, revised Pascal, and the first version of Pascal-P

1974

A new version of Pascal-P is created, termed Pascal-P2

1976

A revised version of Pascal-P in two versions is created, Pascal-P3 and Pascal-P4

1977

The working group for the ISO 7185 standard is formed

1982

The ISO 7185 standard is issued

2009

Pascal-P5 was created.

2023

Pascal-P6 was created.

 


Versions of Pascal-P


The Pascal-P compiler was created in 1973, then went through several versions, which so far have not been available. Ch. Jacobi gives an overview of the Pascal-P versions in PUG newsletter #4:

Name

Origination

Year

Exists?

Description

Repository

Pascal P1

Zurich

1973

No

Either of the early Pascal-P systems (released in March and July 1973 respectively)

 

Pascal-P2

Zurich

1974

Yes

The Pascal-P system released in May 74

https://github.com/samiam95124/Pascal-P2

Pascal-P3

Zurich

1976

No

The new Pascal-P system with the same hypothetical machine as the one underlying the Pascal P2 system

 

Pascal-P4

Zurich

1976

Yes

The new Pascal-P system with a slightly modified hypothetical machine (allowing a more efficient implementation)

https://github.com/samiam95124/Pascal-P4

Pascal-P5

San Jose

2009

Yes

Fully ISO 7185 compliant Pascal-P.

https://github.com/samiam95124/Pascal-P5

Pascal-P6

San Jose

2023

Yes

Pascal with Pascaline extensions.

https://github.com/samiam95124/Pascal-P6

The versions of P1 that existed have (so far) not been available. The revised version, P2, is available, and was used as the basis for the UCSD system. P3 was a "step" implementation used to bridge between P2 and P4, and is also not obtainable.

The last major version of Pascal-P was P4, and that was the most famous (or if you prefer infamous) version. This version would have been referred to as Pascal-P4.


Pascal-P5


Pascal-P4 left off as a subset of the full Pascal language, and it came about years before the ISO 7185 standard. The first step to get p4 running today was to upgrade P4 to ISO 7185 status. It is important to separate the language status of the source code from that of what the compiler generates. Having the source obey ISO 7185 conventions means that it can be compiled and run today. The result would still not compile for ISO 7185 conventions. Indeed, P4 in this form does not compile the language Pascal at all, but a subset of it, as per its design.

The update of P4 to ISO 7185 in this way was fairly simple. In fact, it mainly involved changing the segmented file handling methods of the CDC 6000 implementation to standard Pascal, and the segmented file handling was never part of the language Pascal.

The next obvious step was to have P4 handle the full language Pascal. The original reason for making P4 a subset compiler no longer exists. Memory is no longer in short supply, and even fairly inefficient versions of P4 can be made to run easily. The obvious name for such a version was the Pascal-P5 compiler/interpreter, and such a compiler was created after the ISO 7185 standard came about, on or before 1986.

The "Model Implementation of Standard Pascal" is an interesting compiler/interpreter, which mixes the full documentation for the system into the source as comments. It not only implements the full ISO 7185 Pascal language, but acts as a example implementation of all of the requirements of ISO 7185 Pascal (hence the "model implementation"). It is available only in book form:

A Model Implementation of Standard Pascal. Hardcover.

Unfortunately, the "Model Implementation" disappeared into the BSI or British Standards Institute, where many other important Pascal historical documents have gone. The books bear various vague threats of copyright protection from the BSI, enough to discourage scanning and entering the source of the compiler from the books (just the job of scanning and fixing the resulting source would be massive).

The next possibility for P5 is the most obvious. It is the straightforward improvement of the P4 compiler/interpreter to full Pascal language status. This was done by me in a few weeks, and the result is here, and was improved over the years. P5 shares the same documentation and virtual machine as P4, abet with improvements. It is perhaps %30 larger than the original P4 (and this includes adding the entire table of error messages).


Pascal-P6


Pascal-P6 is an extended version of Pascal, written in unextended Pascal. Although it might seem odd to have a compiler that is written in a subset of the language it processes, it is a common theme in Wirth's compiler series, and forms the basis of the bootstrap method. Although there are many possible language extensions to use, Pascaline is the ideal language for Pascal-P6. It is both current with programming trends (featuring objects, modules, namespace control and parallel programming constructs), and at the same time represents a minimal increment to original Pascal. Pascal-P6 can be constructed for the most part without the use of any element outside of ISO 7185 Pascal (even objects can be interpreted using ISO 7185 Pascal), and the calls that cannot, such has for file handing, can be left to stub routines that are easily changed for a particular implementation. Thus, Pascal-P6 is an ideal extension basis that can be bootstrapped on any ISO 7185 compiler.


For more information contact: Scott A. Moore samiam@moorecad.com