Turbo Pascal Compiler

October 16, 2013

My friend Fredrik Fatemi and I spent the summer after high school (1989) writing graphics programs in Turbo Pascal on his 286 PC (with EGA!) in his basement while watching The Princess Bride again and again on his VCR. He recently found some 3½" diskettes with our programs on it. I couldn’t find a good way to run them on my Mac, so naturally I wrote a Turbo Pascal compiler. It’s web based and you can try it here.

A few notes:

  1. It implements the subset of the language and standard library that I needed to run these five programs. That’s most of the language and a useful subset of the graphics module.
  2. It’s about 6,000 lines of JavaScript code and uses a hand-coded recursive-descent parser.
  3. It compiles to p-code that’s binary compatible with the 1978 UCSD Pascal Compiler. (The real Turbo Pascal compiled directly to machine language.)
  4. For kicks I also implemented a web version of the Turbo Pascal 3.0 menu. Only the Dir, Edit, Work File, and Run commands work. The language and libraries are closer to the later versions, though.

The ROSE.PAS program is our crowning achievement. It’s an animated canvas of a centipede moving slowly toward a golf ball under a rose. It’s really a dumping ground for a bunch of visual experiments, including a fractal mountain. It’s the program I most wanted to see run again.

The SPIDER.PAS program was inspired by a demo on the SGI Iris graphics workstation. That summer Fredrik was an intern at the Naval Research Lab (and still works there today). They had an Iris and he had me drive all the way over there to see this demo, which was written by Thant Tessman and was called “insect” because it only had six legs. I will never forget the shell shock of seeing my first real-time graphics program.

This compiler is the only project I've ever worked on, in my life, which I enjoyed every bit of. It took several weeks of evenings and a few weekends. I think I enjoyed it all because there was always a short-term achievement to unlock: I sorted the five original Pascal programs by complexity and was driven to implement the minimal set of features to see each run in turn. There was no long slog that I had to go through after doing the fun initial part. It was pure delight.

The code of the compiler is on GitHub: Turbo Pascal compiler.

~ See all projects ~