In a random, unscientific sampling of syllabi for recent compiler courses at a dozen universities in the US, I determined that many still use the iconic “dragon book” [1], or older textbooks from as far back as 1995. Several of the syllabi mention the more recent compiler text by Cooper and Torczon [2], but the older books seem to prevail. However, this new book’s fresh, readable, student-friendly text and supporting software make it a serious contender for both self-study and classroom adoption.
While this 350-page book is no replacement for the comprehensive coverage of the 1000-page dragon book, the 800-page Cooper and Torczon text, or a number of other textbooks in compiler design, it allows the reader to quickly become involved in every stage of the compiler construction process. The heart of the authors’ pedagogical approach is having the reader make modifications and additions to a working compiler, written in Java, for a subset of Java that the authors call j--.
In the first chapter, the reader is led through the steps needed to add an integer division operator to j--, from creating the JUnit test files, through augmenting the scanner and parser, to generating the appropriate byte code. Exercises at the end of the first chapter encourage the reader to implement some of the other missing operators by imitating this process. (The “DivisionTest” code in the book is wrong, but the authors have posted an errata file containing corrections to this and other errors.)
The compiler source code is available on the authors’ website. It was easy to install using the instructions provided there, and it worked out of the box. It uses a recursive-descent parser, and includes back-ends for generating both standard Java virtual machine (JVM) byte code and MIPS assembly language. There are compiling options for examining the tokens, the abstract syntax tree, and other intermediate states of the compilation. The j-- language is rich enough to permit fairly sophisticated programs while still allowing much room for experimentation and expansion. For instance, it has integer, Boolean, and string types, but no floating point; it supports Boolean “not” and “and,” but not “or”; it allows “while,” but not “for”; and it permits programs with multiple classes and inheritance, but does not include interfaces.
Much, if not most, of the work required of readers of this book lies in understanding the existing code for the j-- compiler. Consequently, many of the figures in the book consist of Java methods for accomplishing various compiling tasks. Students who would rather write code than read it will prefer to use a different book, but other (perhaps most) readers will appreciate having a stable and robust code base to serve as the foundation for their explorations.
There are separate chapters devoted to the theory of lexical analysis, parsing, and symbol tables and abstract syntax trees, all presented both formally and through the example of the j-- compiler. JVM and MIPS code generation receive a chapter apiece, and another chapter addresses register allocation. Elementary code optimization techniques are described in the MIPS chapter. The concluding chapter surveys several “celebrity” compilers, including a few Java compilers and the Microsoft C# compiler. Each chapter has a rich set of exercises that reinforce the material well. Good software engineering principles are emphasized throughout the book. Two of the five appendices describe the syntax of the Java and j-- languages, and another gives a thorough introduction to JVM and class files.
This would be an excellent book to use for individual study or in an upper-level undergraduate or first-year graduate course. No previous background in the theory of computation is needed, but a solid Java background is essential and some previous experience with programming languages (scope, stack allocation, types, and so on) would be useful. Knowledge of assembly language programming will be helpful if the course will include the chapters on register allocation and translating to MIPS.
More reviews about this item: Amazon