An important aspect of teaching a course in compiler writing is to illustrate
the key theoretical concepts normally taught in such a course. A frequently used
strategy for achieving this goal is to have a student design a simple programming
language and implement a compiler for this language. Many texts in compiler
writing do not, because of size considerations and level of presentation, adequately
present details that illustrate the implementation of a compiler. This book presents,
in a case study manner, the development of a small compiler typical of those
developed in a first compiler course. Instructors can use this book as a guide to
illustrate difficulties that commonly arise when implementing a compiler. They can
also use the guide as an example document that is similar to what students should
produce for their own compilers. It is necessary for instructors that teach a course
in compiler writing to set up their own "toy" compiler as a vehicle for illustrating
techniques for implementing a compiler. Also, many of the problems that are
encountered in writing a compiler for a newly designed language must be
illustrated. This guide is an attempt to fulfill this role.
Although this book has been written to accompany our main text entitled
"The Theory and Practice of Compiler Writing", it can also be used with any other
book that contains the key theoretical concepts of compiler writing. In particular,
this guide requires a basic knowledge of scanners, LL(1) parsing, attributed
grammar translation, error detection and repair, symbol-table methods, run-time
storage management, code generation and interpreters.
This book begins with a documented description of a simple programming
language, GAUSS, which serves as an example for the student. GAUSS is a block-
structured language whose design was influenced by ALGOL, PASCAL, PL/I and
FORTRAN. It also contains string-manipulation facilities capable of manipulating
variable-length strings.
Chapter 2 illustrates the topics of scanner generation, LL(1) parsing,
symbol table construction; code generation, semantic analysis, error detection and
repair for the GAUSS language.
Chapter 3 describes an interpreter for the code generated by the GAUSS
compiler and discusses the run-time environment in which the machine code is
executed. The code generated by the compiler executes on a hypothetical machine
which is stack-oriented. The compiler and interpreter are programmed in PL/I.
We owe a debt of thanks to the many people who assisted in the preparation
of this manuscript and the implementation of the GAUSS compiler and
hypothetical-machine interpreter. Doug Bulbeck and Darwin Peachey assisted in
the design of GAUSS and the implementation of the scanner, parser and the error
handler. Joe Wald contributed to the code generation phase, attribute translation
and the design of the hypothetical machine. Lyle Opseth assisted throughout the
preparation of the manuscript and, in particular, wrote the interpreter for the
hypothetical machine. Beth Protsko assisted in the preparation of the index. We
are also grateful for the comments of our students in the Department of
Computational Science at the University of Saskatchewan, who have class-tested
preliminary versions of the book over the last five years.