Books : reviews

Jim Holmes.
Object-Oriented Compiler Construction.
Prentice-Hall. 1995

rating : 3.5 : worth reading
review : 22 February 1999

This could be subtitled: "writing a Pascal compiler, using lex, yacc and C++". It is good to see a book on compilers that just overviews lexing and parsing, and then effectively says "but don't write your own, just use these existing tools". (The current generation, growing up with "integrated development environments" under Windows, rather than with good old Unix, seems distressingly unaware of these kind of universal development tools.)

It then gets down to the more interesting stuff: symbol tables, parse trees, static semantic analyses, interpreters, code generation (for SPARC assembly language), and optimisation. The emphasis is on getting an object oriented structure, describing the objects and classes involved, and the text is liberally splattered with snippets of C++.

There are some good ideas in here, but I would have preferred to see how the different phases hang together a bit more. For example: writing the recogniser part of a yacc parser is described quite well, including a bit about error recovery and yyerror(), but not much is said about how write the rest of it, about what to do with what you have recognised, about making calls from the yacc code to build the parse tree and the symbol table, using $$, C++ method calls, and so on. (There is an Appendix with a Pascal parser, including the relevant calls.)

So, if you know a bit about compilers, and a bit about object orientation, this will give you enough clues about how to build an OO compiler for a Pascal-like language. But I wouldn't use it as a "teach yourself" introductory text for either.