PDF copy of textbook | Source Code | Courseware | Change List

Compilers and Compiler Generators

an introduction with C++

© P.D. Terry, Rhodes University, 1996, 2021


This site provides an on-line edition of the text and other material from my book "Compilers and Compiler Generators - an introduction with C++", published in 1997 by International Thomson Computer Press. The original edition is now out of print, and the copyright has reverted to me.

The text of the book is now Copyright © PD Terry. Although you are free to make use of the material for study and academic purposes, please do not redistribute it without my knowledge or permission.

Comments, suggestions and questions to Pat Terry.

Adobe® PDF edition

The text of the book is available for download as a compressed set of files in PDF format, which will allow you to view and/or print a copy with Adobe Acrobat or Ghostview. The compressed file is about 1.2MB, but expands to require 8MB of storage.
pdfvers.tgzVersion compressed with tar and gzip
pdfvers.zipVersion compressed with Info-ZIP utility
pdfvers.pdfComplete text in one PDF file (1MB) courtesy of Irwin Oppenheim of the Netherlands.


The latest versions of the software sources for the book are available by clicking on the links shown below.

install.htm        11 Kb  Installation and setup instructions
unzip.exe          11 Kb  Decompressor for *.zip files

common.zip         93 Kb  Files common to all languages
csources.zip      350 Kb  C++ specific sources
msources.zip      345 Kb  Modula-2 specific sources
psources.zip      312 Kb  Pascal specific sources


Much use is made in the book of a tool Coco/R, a compiler generator developed at Linz, Austria, by Hanspeter Moessenboeck and others, based on L- attributed grammars. Coco/R has been through various incarnations, and is available for various languages and systems.

Coco/R combines the functionality of the well-known UNIX tools lex and yacc, to form an extremely easy to use compiler generator that generates recursive descent parsers, their associated scanners, and (in some versions) a driver program, from attributed grammars (written using EBNF syntax with attributes and semantic actions) which conform to the restrictions imposed by LL(1) parsing (rather than LALR parsing, as allowed by yacc). The user has to add modules for symbol table handling, optimization, and code generation in order to get a running compiler. Coco/R can also be used to construct other syntax-based applications that have less of a "compiler" flavour.

Versions are available for Oberon, Modula-2, Pascal, Delphi, C/C++, Java, C#, and Unicon/Icon

Note that this book uses versions of Coco/R that predate the versions of Coco/R used in my later book, and which are available from another section of this website. Development of the earlier versions ceased quite a while ago!

You will need to install an executable version of Coco/R as used in this book:

cocorc.zip        103 Kb  Minimal Coco/R for C
cocorm.zip         76 Kb  Minimal Coco/R for Modula-2
cocorp.zip         65 Kb  Minimal Coco/R for Pascal

fileio.zip        153 Kb  Modula-2 FileIO module

If you are curious, you will find the source code for the versions of Coco/R used in this book (which will allow you to tailor, modify and adapt Coco/R itself) in the three files:

crc117.zip        103 Kb  Coco/R for C version 1.17
crm154.zip        103 Kb  Coco/R for Modula version 1.54
crp154.zip        103 Kb  Coco/R for Pascal version 1.54


Over the years a large volume of "courseware" in the form of exercises, tests, practicals and examinations was developed. Some of this can be found at http://www.cs.ru.ac.za/compilerbook/Courseware/courses/index.html.

All this material is supplied "as is" for external readers, and is a bit of a mixed bag that changed dynamically as my courses proceeded. The course was eventually based on my later book, but some extra tutorial material for the earlier book is still available in my archives.

Change List


While every attempt has been made to ensure that the software made available from this website, and described in this book performs properly, the author can accept no liability for any damage or loss, including special, incidental, or consequential, caused by the use of the software, directly or indirectly.

In particular, the software provided here was originally developed in the 1990s using compilers for C++, Modula-2 and Pascal that were designed for machines and operating systems available at that time. This was the era of "16 bit" systems. Some of the software may not run directly, or at all, on modern "32bit systems" or "64 bit systems" without some prior modification, or the use of virtual machines or machine emulators.


Products and services that are referred to in this book may be either trademarks and/or registered trademarks of their respective owners. The author makes no claim to these trademarks. In particular:

Borland C++, Turbo C++, Delphi and Turbo Pascal are trademarks of Borland International Corporation.
GNU C Compiler is a trademark of the Free Software Foundation.
IBM and IBM PC are trademarks of International Business Machines Corporation.
Microsoft, MS and MS-DOS are registered trademarks, and Windows is a trademark of Microsoft Corporation.
Stony Brook Software and QuickMod are trademarks of Gogesch Micro Systems, Inc.
TopSpeed is a registered trademark of Jensen and Partners, International.
Any other trademarks inadvertently used here are also duly acknowledged.

Also of interest

A complete revision of this book, using C# and Java and the versions of Coco/R for those languages, was published by Pearson Education (Addison Wesley) on 5th November 2004 under the title "Compiling with C# and Java" (ISBN 032126360X).

A feature of this book is that it demonstrates the use of Coco/R to implement compilers for the JVM and CLR platforms.

The original edition of this book is now also out of print, and the copyright has reverted to me. An online copy of the 2004/2005 edition is available here.

Over the years when "Compiling with C# and Java" was used for my compiler course at Rhodes University, an abbreviated version was produced for student use, and some of the material was revised based on this experience. An online copy of the 2017 edition is available here.