Previous    Next


This tutorial is intended as a textbook for a one- or two-semester course in compilers. Students will see the theory behind different components of a compiler, the coding techniques used to put the theory into practice, and the interfaces used to modularize the compiler. To make the interfaces and coding examples clear and concrete, we have written them in Java. Another version of this tutorial is available that uses the ML language. Implementation project The "student project compiler" that we have out-lined is reasonably simple, but is organized to demonstrate some important techniques that are now in common use: abstract syntax trees to avoid tangling syntax and semantics, separation of instruction selection from register allocation, copy propagation to give flexibility to earlier phases of the compiler, and containment of target-machine dependencies. Unlike many "student compilers" found in other textbooks, this one has a simple but sophisticated back end, allowing good register allocation to be done after instruction selection. This second version of the tutorial has a redesigned project compiler: It uses a subset of Java, called MiniJava, as the source language for the compiler project, it explains the use of the parser generators JavaCC and SableCC, and it promotes coding with the Visitor pattern. Students using this version can implement a compiler for a language they're familiar with, using standard tools, in a more object-oriented style. Each chapter in Part I has a coding exercise corresponding to one module of a compiler. Software useful for the exercises can be found at (outside North America); (within North America). Exercises Each chapter has pencil-and-paper exercises; those marked with a star are more challenging, two-star problems are difficult but solvable, and the occasional three-star exercises are not known to have a solution. Course sequence The figure shows how the chapters depend on each other.

Java Click To expand

Acknowledgments Many people have provided constructive criticism or helped us in other ways on this tutorial. Vidyut Samanta helped tremendously with both the text and the software for the new version of the tutorial. We would also like to thank Leonor Abraido-Fandino, Scott Ananian, Nils Andersen, Stephen Bailey, Joao Cangussu, Maia Ginsburg, Max Hailperin, David Hanson, Jeffrey Hsu, David MacQueen, Torben Mogensen, Doug Morgan, Robert Netzer, Elma Lee Noah, Mikael Petterson, Benjamin Pierce, Todd Proebsting, Anne Rogers, Barbara Ryder, Amr Sabry, Mooly Sagiv, Zhong Shao, Mary Lou Soffa, Andrew Tolmach, Kwangkeun Yi, and Kenneth Zadeck.

JaVaScreenshot Previous    Next