Pascal Compiler

Mike DeMoney and I wrote a compiler for a subset of Pascal after writing the parser generator that would compile the compiler.

Mike and I often argued about the best approach for some feature. He was insistent. I sometimes let him have his way. Sometimes he proved to be right. This didn't normally happen to me. I learned to listen better for the experience.

We were advised that we could make a good parser generator and then writing the compiler would be easy. Or we could write a simple parser generator and work harder on our parser. I thought the tradeoff represented some sort of elegant choice and inspired me to recognize refactoring as an important design practice.

We were disappointed that our finished compiler could not run a sample program from Wirth's book. Further investigation showed that his own compiler wouldn't work either. It turned out that the program was sensitive to trailing spaces which were added by the operating system to pad out 12-bit bytes with 6-bit characters. All of his test data had an even number of characters and thus avoided the bug. We were not so fortunate in our choices.

The publisher recently made a pdf of the book available for free download online. springer

I've extracted the relevant program 11.4. pdf