P2 Pascal Compiler

As the name implies, P2 is the second version of the Portable Pascal compiler. It seems to be the first one widely distributed and also the first one to have surviving sources.

One of the distributions of P2 went to California, UCSD. And that version evolved into the UCSD Pascal system.

Mark Rustad took the P2 source, stripped it (no reals e.g.) and changed the p-code to a compact bytecode in Pascal-M.

 (*********************************************************         
  *                                                       *         
  *                                                       *         
  *     STEP-WISE DEVELOPMENT OF A PASCAL COMPILER        *         
  *     ******************************************        *         
  *                                                       *         
  *                                                       *         
  *     STEP 5:   SYNTAX ANALYSIS INCLUDING ERROR         *         
  *               HANDLING; CHECKS BASED ON DECLARA-      *         
  *     10/7/73   TIONS; ADDRESS AND CODE GENERATION      *         
  *               FOR A HYPOTHETICAL STACK COMPUTER       *         
  *                                                       *         
  *                                                       *         
  *     AUTHOR:   URS AMMANN                              *         
  *               FACHGRUPPE COMPUTERWISSENSCHAFTEN       *         
  *               EIDG. TECHNISCHE HOCHSCHULE             *         
  *               CH-8006 ZUERICH                         *         
  *                                                       *         
  *                                                       *         
  *                                                       *         
  *     MODIFICATION OF STEP 5 OF PASCAL COMPILER         *         
  *     *****************************************         *         
  *                                                       *         
  *     THE COMPILER IS NOW WRITTEN IN A SUBSET OF        *         
  *     STANDARD PASCAL  -  AS DEFINED IN THE NEW         *         
  *     MANUAL BY K. JENSEN AND N. WIRTH  - AND IT        *         
  *     PROCESSES EXACTLY THIS SUBSET.                    *         
  *                                                       *         
  *     AUTHOR OF CHANGES:   KESAV NORI                   *         
  *                          COMPUTER GROUP               *         
  *                          T.I.F.R.                     *         
  *                          HOMI BHABHA ROAD             *         
  *                          BOMBAY - 400005              *         
  *                          INDIA                        *         
  *                                                       *         
  *     THESE CHANGES WERE COMPLETED AT ETH, ZURICH       *         
  *     ON 20/5/74.                                       *         
  *                                                       *         
  *                                                       *         
  *********************************************************)        

Original P2 compiler source
Original P2 interpreter source

Scott Moore’s ISO7185 version of P2

Zürich Pascal compilers

The first Pascal compiler was developed during the years 1969-1971 for Control Data 6000 series hardware at the Institut für Informatik, Eidgenössische Technische Hochschule Zürich. As result of experience with the system and a new implementation begun in July, 1972, resulting in a family of two compilers, Pascal_P and Pascal-6000, having a single overall design.

Pascal-P is a portable compiler that produces code for a hypothetical stack computer, the system is implemented by writing an interpreter for this machine.

Pascal-6000 produces relocatable code for Contrl Data 600 series computers.

Descendants of these two compilers comprised the bulk of the Pascal implementations in existence after 1980.

CDC 6000 Pascal compilers

Pascal Px compilers

Pascal-S compiler

Pascal PL/0 compiler

See the Articles and Books pages for more information!

CDC 6000 Pascal compilers

The CDC 6000 compiler was used as the basis for several other compilers on other machines. When a Pascal implementor needed a compiler, he/she could use either the P4 source as a basis, or the CDC 6000 compiler, or write it from scratch. The reason you might prefer to use the machine specific CDC 6000 compiler as a starting point is that (unlike the P4 compiler) it was a full implementation of Pascal, without any features left off. It also was a full optimizing compiler.

Read this report written by Niklaus Wirth, On “PASCAL” Code generation, and the CDC6000 Computer, Stanford University, 1972

On this page listings from 1972, 1974, 1976 of the Zürich compilers and the surviving (1986) CDC 6000 compiler at Minnesota University.

The 1972 Compiler

The following listing was provided by John Reagan, currently Master Compiler Engineer at VMS Software, formally of Digital Equipment (DEC), Compaq and HP.
Main compiler code in Pascal
The 1972 Compiler was the last version of the original, unrevised Pascal language before Pascal reached the form most folks know as Standard Pascal. It is different in many ways, for example, there was no program header, write/ln and read/ln were considered CDC extentions to the language, dynamic pointers were introduced by a statement, and other differences.
The language of the compiler is described in the 1970 document, see the Articles page.
The method used to create the first Pascal compiler, described by U. Ammann in The Zurich Implementation, was to write the compiler in a subset of unrevised Pascal itself, then hand-translate the code to SCALLOP, a CDC specific language. The compiler was then bootstrapped, or compiled using the Pascal source code and the SCALLOP based compiler, to get a working compiler that was written in Pascal itself. Then, the compiler was extended to accept the full unrevised Pascal language.

The 1974 compiler

The following listings were scanned from listings provided by Bob Felts: CDC 6000 Pascal 3.4 Update 10 compiler.
Main compiler code in Pascal
Cross-reference
Runtime library code in Compass, the CDC 6000 assembly language
The 1974 compiler was the first of the revised compilers. That is, it was rewritten in the “revised Pascal” language that was the Pascal language we recognize today. The “Pascal-P implementation notes” imply that the compiler was Pascal-P ported specifically to the CDC 6000 series computer, and indeed the 1974 CDC Pascal compiler appears to match P2 better than any of the other compilers. As the CDC compiler was modified, it resembled Pascal-P less and less, which is natural.

The 1976 Compiler

The following listings were scanned from listings provided by Mr. John Dykstra.
Main compiler code in Pascal
Runtime library code in Pascal
Runtime library code in Compass, the CDC 6000 assembly language
An error translation routine
The compiler listing is dated 1976. The scans were taken from a listing direct from a CDC 6000 series computer, and bear some unique features to such a listing. The name and line number appears at the right of the listing. Because the listings were wider than a 8 1/2 inch sheet of paper the line numbers to the right have one or more digits cut off. This compiler comes from the revised Pascal that forms the basis of the Pascal User Manual and Report, second edition. The compiler source is not written in standard Pascal, nor would it have been even if the compiler had been written at the time of the standard. It uses several of the CDC 6000 specific extentions, and it has the generation of CDC 6000 machine instructions imbedded in it. It is a one piece compiler, it takes in Pascal on one end, and issues CDC 6000 object code out of the other. The layout of the compiler is similar to the P4 project, which is not an accident. The P4 system was derived from this compiler. The compiler was written in, and compiled for, the revised Pascal language that most of us think of as Standard Pascal. The documents that describe this are described on the Articles page.
U. Ammann described the creation of the revised compiler in The Zürich Implementation, The 1970 compiler (above) was rewritten completely to arrive at the revised Pascal compiler. This was done both because the new Pascal language was different, and also because the experience of writing the old compiler had suggested better code structure for the new compiler. The new compiler was written in unrevised, or 1970 Pascal code. This resulted in a compiler that compiled using the old compiler, but accepted the revised language Pascal. Then, the compiler code itself was hand translated to the new language, and translated by the new compiler that was compiled by the old compiler. This resulted in the new compiler running on itself, and thus a full bootstrap. Of course, at this point you might well wonder what hand translation of the first version of the source on the new compiler from unrevised to revised Pascal might mean, which U. Ammann does not go into. Basically, it is just what you do if the unrevised and revised languages are not quite compatible. Otherwise, if the unrevised compiler was a subset of the revised language, you could just recompile it without changes. This is not nearly as much of a project as translation to SCALLOP, and used in the first compiler. It just means changing to accommodate the differences in the languages, which were substantially similar.

The 1984 Compiler

The CDC compiler continued to evolve past 1976. Most of the changes in what is contained here as the 1984 compiler were made at the University of Minnesota by Dave Bianchi and Jim Miner (who appears as a reviser of the forth edition Pascal User manual and Report). The material contained is marked copyright, but the University of Minnesota has graciously granted permission for it to appear. The University of Minnesota group extended the implementation in a few ways, for example it contains the otherwise statement on case statements. Otherwise, it appears to be a straightforward implementation of the original Zürich compiler, and it continued to be run on the CDC 6000 series computers. The University of Minnesota implementation is important for several reasons:

  • It contains the last known code revision of the CDC compiler.
  • It is well documented.
  • It is exists in machine readable and runnable form.
  • It obeys, with compiler options, the ISO Pascal Standard.

Modification history – History of changes to the source.
Pascal compiler – The main compiler code
Pascal Include Generator – Program to process includes and error information.
Pascal Library – Contains runtime support library routines in Pascal.
Pascal Error Messages – Contains error messages in various languages.
Pascal Runtime Support – Contains Pascal runtime support in Compass, the CDC 6000 assembly language.
Pascal System Support -Contains the run time system in Compass, the CDC 6000 assembly language.
Pascal System Texts – Contains constants and macros used in the compiler, in Compass.

Note that the listings were created by a card listing program (as in punched cards), and have type and sequencing information at the right hand side. This information can be easily removed by clipping everything from column 75 on. It was retained here for historical purposes.
Note also that all of the sources appear in upper case text. The CDC computer native character instruction set only had one case of character.

The documentation files for the compiler:
Pascal-6000 Installation Handbook – Details how to install the release tape.
Pascal-6000 Internal Reference Manual – Overview of program internals.
Pascal-6000 Library Information – Details of the local library.
PASPLOT – a Pascal Plotting Package – Details of an applications package.
SUMMARY OF CHANGES TO PASCAL-6000 – As it says.surveys changes from the last to this release
Pascal-6000 Release 4 Upgrade Guide
Prose Instruction Manual – Manual for Prose, a text formatter.
Pascal-6000 Writeup – The main users manual for the compiler.

Based upon a page and files supplied by by Scott A. Moore

P4 Pascal Compiler


Relevant articles about the portable Pascal Px compilers (see also the Articles page for Pascal Reports etc)

Book by Martin Daniels and Steven Pemberton Pascal implementation: The P4 Compiler, online version, local copy
A line by line description of the source.

ETH Pascal Programming Language Technical information:

Portable Compiler project New Edition H.H. Naegeli, 16.02.77
Portable Compiler project Pascal P4 Urs Ammann, Kesav Nori, Christian Jacoby May 76
Pascal P4 interpreter
Lists binary codes P-codes
Cross referencer
P4 Pascal Compiler P-Code listing
Procedural Cross Referencer

Downloads

Pascal P4 adapted to more standard Pascal
The files in this archive are:

  • int.p – P4 code interpreter
  • comp0.p – original compiler as distributed
  • comp1.p – same compiler with bugs fixed up to Pascal Newsletter #12
  • comp2.p – as above but with experimental changes to eliminate the last of the machine dependent code
  • comp.p – lower case, entabbed and stripped version of comp2.p some typos in comp?.p have been fixed
  • compvax.p – essentially the same as comp.p but with changes to allow it to compile under ‘pc’
  • compdiffs – differences between compvax.p and comp.p
  • compvax.errs – warning messages
  • compvax.map – line numbers of procedures and functions

Note that the characters for ^ and ‘ are ‘ and # in the compiler sources.

Pascal P4 adapted to ISO7185 Pascal by Scott Moore

Pascal P4 adapted to more standard Pascal, with examples

Pascal-S Concurrent Pascal-S

Pascal-S is a subset of Pascal, and was originally written by Niklaus Wirth.
Moti Ben-Ari has built on Pascal-S in his Principles of Concurrent Programming, resulting in Concurrent Pascal-S.

Compared to Wirth’s version of Pascal-S, case statement, records and reals are swiped from this edition of Pascal-S. M. Ben-Ari modified Wirth’s original compiler/interpreter in 1980 to include some basic features that were able to simulate concurrent programming.

First, a cobegin s1; …; sn coend block structure was added, allowing concurrent execution of the statements s1 … sn, which were required to be global procedure calls. These cobegin … coend blocks could not be nested within one another.

Second, the use of semaphores was introduced, with a semaphore data type (really synonymous with the integer data type) and the semaphore operations wait(s) and signal(s), corresponding to Dijkstra’s P(s) and V(s), respectively.

Downloads:

post

Pascal-S

Pascal-S is a subset of Pascal selected for introductory programming courses. The implementation is especially designed to provide comprehensive and transparant error diagnostics and economical service for small jobs.
The system consists of a compiler and an interpreter and is defined as a single, self-contained Pascal program.
Pascal-S is written in Pascal, and forms an excellent introduction to the art of designing small compilers.

Ben-Ari built on Pascal-S in the first version of his “Principles of concurrent programming” and introduced concurrency, see the Pascal-S Copascal page.

It is a interesting to see how many CDC-Pascal specialities are built into this compiler/interpreter.

  • Keywords are recognized by a binary search through a list of alfa’s (a standard datatype in CDC-Pascal) which are a 60-bit machine word packed with 10 6-bit characters. Since both DO and DOWNTO are keywords it is apparent from the ordering of the list that space comes after letters in the CDC character set <.li>
  • Some of the handling of large integers will only succeed on a CDC pascal implementation programs data gave the desired results
  • In Simpleexpression a 36 is emitted to negate both reals and integers, but the interpreter does this for both reals and integers s(.t.).i := – s(.t.).i;
    On the CDC this actually works for reals too

Corrections to the original (Jan van de Snepscheut):

  • line 295 (counting from 1 starting at program Pascal-S) is
    gen1(mulc, ttab[t].size); gen0(add)
    whereas the version printed in the book accidentally reads
    gen1(mulc, ttab[t].size)
    the corrected versions also implements boolean negation
  • the procedure funcdeclaration in the version printed in the book is
    erroneous. The first line on page 376 in the book should read
    if lev>1 then dx:=-1
    the last line of the procedure should read
    gen1(exit,itab[f].resultadr-dx); lev:=lev-1; dx:=odx

Wirth’s original paper is reprinted in Barrons book. Another version of Pascal-S appears in Snepscheut’s book and this uses symbolic names and contains a small peephole optimizer.
Publications where Pascal-S appeared in source format are:

  • PASCAL-S: A Subset and its Implementation, by Niklaus Wirth, Zurich : Eidgenossische Technische Hochschule, 1975. 61 s., Berichte des Instituts fur Informatik;
  • Pascal – The Language and its Implementation, by D. W. Barron, Chichester :
    John Wiley and Sons, 1980. 201 s. , ill., Wiley Series in Computing
  • Principles of Concurrent Programming, by M. Ben-Ari, Englewood Cliffs, N.J. :
    Prentice-Hall, Inc., 1982, 172 s. , ill.
  • What Computing is All About, by Jan L. A. van de Snepscheut



Downloads:


Some information on this page has been published by Scott Moore on the Standard Pascal pages and by Birger Nielsen (pages now lost).

Articles by Wirth et al

Collection of mostly historical articles on Pascal, by Niklaus Wirth and others. From the Pascal compilers to recollections.

On certain Basic Concepts of Programming Languages, Wirth, May 1967
What can we do about the Unnecessary Diversity of Notation for Syntactic Definitions?, Wirth, 1977

An Axiomatic Definition of the Programming Language Pascal, Wirth, Hoare, November 1972
A Collection of Pascal Programs Wirth, Wirth, July 1979
Data Structures and Algorithms Informatics, Wirth August 1984
Error Recovery in Descent Parsers, Urs Ammann. Mai 1978
Implementations of Pascal on Systems With No Control Characters, Wirth, June 1973
The Programming Language Pascal (Revised Report), November 1972
On Code Generation in a PASCAL Compiler, Urs Amnann
On Code Generation in a PASCAL Compiler, Urs Amnann, eth-3056-01
Pascal-P Compiler Implementation Notes, K.V. Nori, Urs Ammann, Christian Jacobi, 1974
Planned Changes To The Programming Language PASCAL, Wirth, June 1972
P-Machine Description, ETH, Januari 73
Program development by step-wise refinement, Wirth, January 1971
The Zurich Implementation, Urs Amman
The Pascal(P) Compiler:_Implementation_Notes, K.V. Nori, U. Ammann, K.Jensen, H.H. Naegeli, Dec 1974
The Programming Language_Pascal, Wirth, 1970
The Programming Language Pascal (Revised Report), Wirth, November 1972
The Programming Language_Pascal (Revised Report), Wirth, July 1973
A Pascal processor Validation Suite, Wichman, Sale, March 1980
Pascal Newsletter May 1974
Page 1 History of Pascal documented. Page 6 Wirth describes Pascal 6000-3.4. Page 18 Wirth describes Pascal-P (the P-machine, probably P1)
Program development by step-wise refinement, Wirth, January 1971
On the Composition of Well-structured Structured Programs, Wirth, 1974
Effective Technology transfer, Wirth 1995
Essay on programming, Wirth, March 1999
Programming Languages_What To_Demand And How To Assess Them, Wirth, April 1976
Recollection On the Development of Pascal, Wirth, 1993
Recollection On the Development of Pascal, Wirth 1993
Recollection On the Development of Pascal, Wirth 1983

A Plea for Lean Software, Wirth, February 1995
Good Ideas, Through the Looking Glass, Wirth, 2006
Good Ideas, Through the Looking Glass, Wirth, 2005
On the Design of Programming Languages, Wirth, 1974
Turing Award, Wirth, 1984
Type Extensions, Wirth 1988
What can we do about the Unnecessary Diversity of Notations for Syntactic Definitions, Wirth ,1977
A plea for Lean Software, Wirth, February 1995
Zwanzig Jahre Institut Informatik. F. Bauer, Edsger Dijkstra, 1988
Finite State Machines, Programmable Logic Devices, and the Crux of Growing Complexity, 2008
The Year of Informatics, 2008
Computers and Computing A Personal Perspective, December 2015
A Triptychon of Digital Circuits, August 2005
Was ist ein Denkplatz, und warum erstreben wir ihn?
Als Computer noch erklärbar waren, 2008
A Brief History of Software Engineering, 2008
A Note on Division, 2008
An Essay on Programming, 1999

Carlo Pescio A Few Words with Niklaus Wirth Software Development, Vol. 5 No. 6, June 1997

Lilith section updated

I have added the repository by Jos Dreesen on Lilith and the Emulith emulator with a local copy.
Jos maintains a ftp with just the files, I made it available as web pages here with higher availability and easier viewing of images and videos.

Emulith

Px compilers

Details about the Px compilers:

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 Source Description
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
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)

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.

The last major version of Pascal-P was P4.