Remix.run Logo
dtoffe an hour ago

To all interested in this little treasure, I transcribed the source code of the PL/0 compiler from the book "Algorithms + Data Structures = Programs", published by Nicklaus Wirth in 1976, and adapted it to run in Free Pascal.

You can find the sources here: https://github.com/dtoffe/adsp-pl0

Some interesting notes:

- The original compiler does not define nor implements "read" or "write" statements, as was the norm in later PL/0 implementations. - The source code in the book corresponds to the implementation in the CDC 6000 that Wirth had at hand back then. That machine used the CDC Display Code:

https://en.wikipedia.org/wiki/CDC_display_code

a 6 bit character code from before the ASCII times. Among its 64 characters, it includes single symbols for "<>", "<=" and ">=". In an attempt to change the code the least to make it run as original as possible, I changed those three character to #, { and }, as the symbols in the lexer are implemented using an array of char (only the assignment is treated as a special case).

- The interpreter printing out the values of every variable assignment, noted by another reader of this post, was a way of getting some information of the running program, since the compiler does not implement read or write statements.

- Following the compiler code, full of single letter variable names, was not the most exciting part.