Appendix A

Sources | Unpacking the software | FileIO library | Case studies | Coco/R distributions | Other resources

Software resources for this book

(This appendix is a considerably modified version (6 February 2003) of the one that appeared in the printed book. For interest, the original one can be found here.)

A.1 Source code for the programs

The software that accompanies this text was originally developed in Modula-2. It was subsequently converted to Turbo Pascal, and to C++. Although C++ code is used for most of the illustrations in the text, highly self-consistent source code in all three languages is to be found in this distribution, along with language-specific implementation notes.

The C++ source code was mainly developed under MS-DOS using Borland C++ 3.1. It has also been successfully compiled under Linux, using G++, the GNU C compiler. Although many of the case studies have also been tested with Turbo C++ 3.1, there appears to be a bug in that compiler that prevents the template set class from compiling correctly.

The Turbo Pascal source code was developed to run on any version of Turbo Pascal from 5.5 onwards (although Delphi users should read the notes on Delphi below). However, it makes little use of OOP extensions.

The Modula-2 source code should be immediately usable on MS-DOS based systems using the shareware compiler marketed by Fitted Software Tools (FST), the Stony Brook Modula-2 compiler marketed by Gogesch Micro Systems, Inc., or the TopSpeed Modula-2 compilers developed by Jensen and Partners International (JPI). Provided the appropriate version of the I/O module FileIO is used, it should also compile unchanged on XDS and Stony Brook ISO-compliant compilers, and under Gardens Point Modula-2 on a wide range of systems.

The software in the distribution is currently supplied in the form of compressed, self-extracting MS-DOS executable files within a "zip" wrapper. There are eight of these files.

cocorc.exe        103 Kb  Minimal Coco/R for C          (Updated 2002)
cocorm.exe         76 Kb  Minimal Coco/R for Modula-2   (Updated 2002)
cocorp.exe         65 Kb  Minimal Coco/R for Pascal     (Updated 2002)

common.exe 93 Kb Files common to all languages (Updated November 1999) csources.exe 350 Kb C++ specific sources (Updated November 1999) msources.exe 345 Kb Modula-2 specific sources (Updated November 1999) psources.exe 312 Kb Pascal specific sources (Updated November 1999) fileio.exe 153 Kb Modula-2 FileIO module (Updated November 1999)
All of the sources above
lha213.exe 43 Kb LHArc decompressor readme.1st 11 Kb Installation and setup instructions

A.2 Unpacking the software

To unpack the software, simply follow the steps below. Example MS-DOS commands are shown (these may need alteration, depending on the configuration of your computer). Windows users may follow an equivalent sequence of operations from within the File Manager or Explorer. The files may also be unpacked directly on other systems using appropriate ports of LHA.

Unpacking the case study software


Unpacking the compiler generator Coco/R


A.3 The FileIO library (Modula-2 users only)

When this book was first published, standardized I/O for Modula-2 was not yet widely available (and was incompatible with extant Modula-2 compilers). The Modula-2 source code in this distribution attempts to get around this problem by providing (another!) I/O module, called FileIO. The definition module for FileIO is acceptable to all compilers tested so far; implementations have been supplied for each that differ internally only in a few places.

FileIO provides the usual services for opening and closing text files, and for reading and writing strings, words, whole numbers and line marks to such files. It can also handle random access binary files, as block read and write operations are provided. In addition there are some utility procedures, for obtaining command line parameters and environment strings, and for the output of dates and times. The module is of fairly widespread applicability beyond the confines of this text, and is compatible with the modules generated by Coco/R (which assumes the module to be available). As an example of a library module it is really rather too large, but has been developed in this way to minimize the number of non-portable sections and modules needed for implementing the programs in the book.

Modula-2 scanners, parsers, and compilers created by Coco/R assume that you will use the I/O module FileIO. If you are a Modula-2 user, you will thus need to install and compile the version of FileIO that matches your compiler.

Among the resources you will find a self-extracting file FILEIO.EXE that contains the sources of FileIO for a variety of Modula-2 compilers.

The sources supplied will act as models of implementations for compilers not mentioned above. In case of difficulty, please contact the author.

A.4 Setting up the software for a particular case study

Installation of many (but not all) of the case studies requires you simply to


The Turbo Pascal case studies, and the output from Coco/R for Pascal will not compile directly under Delphi. They require WinCrt to be added to the list of units "used" (edit the compiler frame files for Coco/R). Furthermore those systems (like the assemblers and compilers) that provide for interactive input/output in their interpreters require use of WinCrt.AssignCrt instead of the current calls to Assign with an empty filename (for example in STKMC.PAS and MC.PAS).

A.5 Coco/R distributions

The compiler generator Coco/R used in this book was originally developed in Oberon by Hanspeter Mössenböck, who also did a port to Modula-2 for the Apple MacMeth system. A further port was done to TopSpeed Modula-2 by Marc Brandis and Christof Brass. This was refined and extended by the author in conjunction with John Gough and Hanspeter Mössenböck, to the point where a single version runs on most Modula-2 compilers available under MS-DOS, as well as the Mocka and Gardens Point compilers available for Unix (and other) systems, including Linux and Free BSD.

A port of Coco/R to Turbo Pascal was done by the author in conjunction with Volker Pohlers.

Coco/R was ported to C by Francisco Arzu, yielding a version that can generate either C or C++ compilers.

Coco/R has also been also ported to Java by Hanspeter Mössenböck.

For details of how to obtain the latest versions of the complete Coco/R distributions for a variety of languages and operating systems visit the Coco/R home page at

The original report on Coco/R (Mössenböck, 1990a) can be obtained from

Professor Mössenböck may be contacted at the address below

Prof. Hanspeter Mössenböck
Institute of Computer Science
University of Linz
Alternbergerstr 69,
A-4040 Linz, Austria
Tel: +43-732-2468-9700
e-mail: [email protected]

A.6 Other compiler tools, free compilers and similar resources

The subject of compiler writing and the development of compilers is one of the classical fields of Computer Science for which there are now many freely available resources. The interested reader might do worse than to explore some of the following leads:

FAQ's, topics and archives from the Comp.Compilers news group
The German National Resource Centre catalogue of compiler construction tools
Idiom Consulting's catalogue of free compilers
Compiler Connection
Burks (Brighton University Resource Kit for Students)
Dragon Fodder
Jack Crenshaw's "Let's build a compiler"

The PCCTS compiler construction kit mentioned in Chapter 10 is available from

Freely available early versions of the Cocktail compiler construction tools mentioned in Chapter 10 may be obtained by anonymous ftp from

For the commercial version and support visit or contact Josef Grosch.

mtc, the Modula-2 to C translator program mentioned in Chapter 2 is available by anonymous ftp from

p2c, the Pascal to C translator program mentioned in Chapter 2, and cperf, the perfect hash function generator mentioned in Chapter 14, are available by anonymous ftp from any of the sites that mirror the Free Software Foundation GNU archives. The primary server for these archives is at Among many others, the Linux sites, such as those at or and also carry copies of the GNU archives.

Also to be found among these archives is gcc, the well-known GNU C compiler, which can also be found at or at one of many mirror sites

As another example of a freely available C compiler, lcc is a retargetable compiler for ANSI C described in "A Retargetable C Compiler: Design and Implementation" by Fraser, Hanson and Hansen (Benjamin/Cummings, 1995). lcc is available, along with documentation and a sample chapter of the book at


Versions of the Gardens Point Modula-2 compiler for DOS, Linux and FreeBSD are available from

Versions of the Mocka Modula-2 compiler for Linux and FreeBSD are available from

The shareware FST Modula-2 compiler for MS-DOS systems is available by anonymous ftp from

The self-extracting files in this distribution were compressed and packed using the freely available program LHA.EXE developed by Haruyasu Yoshizaki. In terms of the distribution agreement for this program, the complete package for LHA.EXE is itself supplied as a self-extracting executable, LHA213.EXE. You are quite welcome to unpack this file, although it is not needed for the operations described above.

Further to comply with the distribution agreement, the copyright notice for this package is given below

  4. Our distribution Policy

     This software, this document and LHA.EXE, is a copyright-reserved free
     program.  You may use, copy and distribute this software free of charge
     under the following conditions.

  1. Never change Copyright statement.

  2. The enclosed documents must be distributed with as a package.

  3. When you have changed the program, or implemented the program for other
     OS or environment, then you must specify the part you have changed.  Also
     make a clear statement as to your name and MAIL address or phone number.

  4. The author is not liable for any damage on your side caused by the use of
     this program.

  5. The author has no duty to remedy for the deficiencies of the program.

  6. When you are to distribute this software with publications or with your
     product, you have to print the copyright statement somewhere on the disk
     or on the package.  You cannot distribute this software with
     copyprotected products.


While every attempt has been made to ensure that the software in this distribution 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.

However, please bring any problems that you may experience to the attention of the author:

Pat Terry
Computer Science Department
Rhodes University
South Africa
Tel: +27-46-622-8292
FAX: +27-46-636-1915
e-mail: [email protected]


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.

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.

Contents (GIF version) | Contents (Symbol Font version) | Home  © P.D. Terry