In order to reduce the complexity of designing and building computers, nearly all
of these are made to execute relatively simple commands (but do so very quickly).
A program for a computer must be built by combining these very simple commands
into a program in what is called machine language. Since this is a tedious and errorprone
process most programming is, instead, done using a high-level programming
language. This language can be very different from the machine language that the
computer can execute, so some means of bridging the gap is required. This is where
the compiler comes in.
A compiler translates (or compiles) a program written in a high-level programming
language that is suitable for human programmers into the low-level machine
language that is required by computers. During this process, the compiler will also
attempt to spot and report obvious programmer mistakes.
This textbook is intended for an introductory course on Compiler Design, suitable for use in an undergraduate programme in computer science or related fields. Introduction to Compiler Design presents techniques for making realistic, though non-optimizing compilers for simple programming languages using methods that are close to those used in "real" compilers, albeit slightly simplified in places for presentation purposes. All phases required for translating a high-level language to machine language is covered, including lexing, parsing, intermediate-code generation, machine-code generation and register allocation. Interpretation is covered briefly. Aiming to be neutral with respect to implementation languages, algorithms are presented in pseudo-code rather than in any specific programming language, and suggestions for implementation in several different language flavors are in many cases given. The techniques are illustrated with examples and exercises. The author has taught Compiler Design at the University of Copenhagen for over a decade, and the book is based on material used in the undergraduate Compiler Design course there. Additional material for use with this book, including solutions to selected exercises, is available at http://www.diku.dk/~torbenm/ICD