Chapter 2: A Simple Compiler


In this chapter we provide an overview of the compilation process by considering a simple translation task for a very small language. This language, called AC for adding calculator, accommodates two forms of numerical data types, allows computation and printing of numerical values, and offers a small set of variable names to hold the results of computations.

To simplify both the presentation and implementation of a compiler, we break the compilation process into a sequence of phases. Each phase is responsible for a particular aspect of the compilation process. The early phases analyze the syntax of the input program with the goal of generating an abstract representation of the program's essential information for translation. The subsequent phases analyze and transform the tree, eventually generating a translation of the input program in the target language.

The AC language and its compilation are sufficiently simple to facilitate a relatively quick overview of a compiler's phases and their associated data structures. The tools and techniques necessary for undertaking translation tasks of a more substantial nature are presented in subsequent chapters.