PL/0, Part 1: The whole original language

Finally after years of procrastination I've finally finished implementing PL/0. It took a little over a day, and the code can be accessed here. I was going to work on the parser generator part of Crimson but the hyperfixation and seasonal depression got the better of me.

Why now out of all the time?

I've been planning to implement a very basic early-MSDOS-like operating system in ECMA Minimal BASIC for a video so I needed a BASIC compiler that compiles to 8086 machine code; turns out there's too many stuff to do, way too many for a weekend project; and as I was trying to think of an alternative PL/0 popped into my mind so here we are.

How is this only part 1?

PL/0 is a very small and simple language; one can do many modifications on it:

  • The VM is accomodated to support PL/0's support for nested procedures and is thus not as similar as real-life machines as one would like; technically, the original implementation of PL/0 (described in Wirth's book) does not have a separate "flattening" (or lambda-lifting, to use the actual technical term) pass for simplicity, and thus required a slightly different stack frame layout and a slightly different way to access stack-allocated variables and handle procedure calls & returns; the instruction of the VM accomodated this by having an additional bit field.
  • PL/0 procedures cannot take arguments, which sometimes force the programmer to use global variables; one would at least modify the language so that it supports procedures that takes arguments.
  • Also, PL/0 procedures cannot return values and cannot be used in expressions.
  • There is only one single type, and there is only scalar type; one would at least like to add a character type and an array type.

Where are we going with this?

The plan is as follows:

  • Solve all the problems listed above; this should give us a much more advanced superset of PL/0. It doesn't make sense to write anything serious in PL/0 (not that you actually can), it will make sense to write something in this superset.
  • Add support for records and enums.
  • Switching from a stack VM to a register VM.
  • Add support for pointers.
  • Add support for tagged unions.


Last update: 2024.3.1