Compiling with C# and Java - complete online copy (2005)

P.D. Terry, Rhodes University

A complete revision of my earlier book (Compilers and Compiler Generators (1997)), using C# and Java and versions of the compiler generator Coco/R for those languages, was published as "Compiling with C# and Java" by Pearson Education on 5th November 2004. Following standard publisher practice, the book records a publication year of 2005, and the ISBN is 0-321-26360-X.

(17 April 2021)

This book is now out of print, and the copyright and distribution right have returned to me.

Download a ZIP file containing all the files for this edition.

Complete text as a single PDF file


HTML PDF     Contents

HTML PDF     Preface and Acknowledgements

HTML PDF     Chapter Objectives

HTML PDF     Chapter Exercises

HTML PDF     Chapter 1 - Translators and Languages

1.1 Objectives
1.2 Systems programs and translators
1.3 The benefits of using high-level languages
1.4 The curse of complexity
1.5 Successful language design
1.6 The benefits of formal description

HTML PDF     Chapter 2 - Translator Classification and Structure

2.1 T-diagrams
2.2 Classes of translator
2.3 Linkers and Loaders
2.4 Phases in translation
2.5 Multi-stage translators
2.6 Interpreters, interpretive compilers, and emulators
2.7 The P-system and the JVM
2.8 JIT compilers and the .NET Framework

HTML PDF     Chapter 3 - Compiler Development and Bootstrapping

3.1 Using a high-level translator
3.2 Using a high-level host language
3.3 Bootstrapping
3.4 Self-compiling compilers
3.5 The half bootstrap
3.6 Bootstrapping from a portable interpretive compiler
3.7 A P-code assembler
3.8 The use of compiler generating tools

HTML PDF     Chapter 4 - Stack Machines

4.1 Simple machine architecture
4.2 ASSEMBLER languages
4.3 Addressing modes
4.4 The PVM - a simple stack machine
4.5 Programming the PVM
4.6 An emulator for the PVM
4.7 A minimal assembler for PVM code
4.8 Enhancing the efficiency of the emulator
4.9 Error handling in the PVM
4.10 Enhancing the instruction set of the PVM
4.11 Another stack machine - the JVM
4.12 The CLR - a conceptual stack machine

HTML PDF     Chapter 5 - Language Specification

5.1 Syntax, semantics, and pragmatics
5.2 Languages, symbols, alphabets and strings
5.3 Regular expressions
5.4 Grammars and productions
5.5 Classic BNF notation for productions
5.6 Simple examples
5.7 Phrase structure and lexical structure
5.8 ε-productions
5.9 Extensions to BNF
5.10 Syntax diagrams
5.11 Formal treatment of semantics

HTML PDF     Chapter 6 - Development and Classification of Grammars

6.1 Equivalent grammars
6.2 Case study - equivalent grammars for describing expressions
6.3 Some simple restrictions on grammars
6.4 Ambiguous grammars
6.5 The Chomsky hierarchy

HTML PDF     Chapter 7 - Deterministic Top-Down Parsing

7.1 Deterministic top-down parsing
7.2 Restrictions on grammars so as to allow LL(1) parsing
7.3 The effect of the LL(1) conditions on language design
7.4 Case study - Parva

HTML PDF     Chapter 8 - Parser and Scanner Construction

8.1 Construction of simple recursive descent parsers
8.2 Case study - a parser for assignment sequences
8.3 Other aspects of recursive descent parsing
8.4 Syntax error detection and recovery
8.5 Construction of simple scanners
8.6 Case study - a scanner for Boolean assignments
8.7 Keywords and literals
8.8 Comment handling
8.9 LR parsing
8.10 Automated construction of scanners and parsers

HTML PDF     Chapter 9 - Syntax-directed Translation

9.1 Embedding semantic actions into syntax rules
9.2 Attribute grammars
9.3 Synthesized and inherited attributes
9.4 Classes of attribute grammars
9.5 Case study - a small student database

HTML PDF     Chapter 10 - Coco/R: A Detailed Guide

10.1 Coco/R - a brief history
10.2 Installing and running Coco/R
10.3 Case study - a simple adding machine
10.4 Overall form of a Cocol description
10.5 Scanner specification
10.6 Parser specification
10.7 The driver program

HTML PDF     Chapter 11 - Coco/R - Case Studies

11.1 Case study - Understanding C declarations
11.2 Case study - Generating one-address code from expressions
11.3 Case study - Generating one-address code from an AST
11.4 Case study - Manipulating EBNF productions
11.5 Case study - A simple assembler for the PVM
11.6 Further projects

HTML PDF     Chapter 12 - A Parva Compiler - the Front End

12.1 Overall compiler structure
12.2 Source handling
12.3 Error reporting
12.4 Scanning and parsing
12.5 Syntax error recovery
12.6 Constraint analysis
12.7 Further projects

HTML PDF     Chapter 13 - A Parva Compiler - the Back End

13.1 Extending the symbol table entries
13.2 The code generation interface
13.3 Using the code generation interface
13.4 Code generation for the PVM
13.5 Towards greater efficiency
13.6 Other aspects of code generation
13.7 Further projects

HTML PDF     Chapter 14 - A Parva Compiler - Functions and Parameters

14.1 Source language extensions
14.2 Constraint analysis
14.3 Run-time storage management
14.4 Putting it all together
14.5 Mutually recursive functions
14.6 Nested functions
14.7 Heap management
14.8 Further projects

HTML PDF     Chapter 15 - A C#Minor Compiler - the Front End

15.1 The source language - C#Minor
15.2 The target language
15.3 The symbol table
15.4 Abstract syntax design
15.5 Abstract syntax tree construction
15.6 Parsing declarations
15.7 Further projects

HTML PDF     Chapter 16 - A C#Minor Compiler - the back end

16.1 Single-pass compiler strategy
16.2 Generating code for statements from an abstract syntax tree
16.3 Generating code for expressions from an abstract syntax tree
16.4 Low-level code generation - the CodeGen class
16.5 The OpCode class
16.6 Tracking the depth of stack
16.7 Generating the directives
16.8 Further projects

HTML PDF     Appendix A - Assembler programmer's guide to the PVM, JVM and CLR

HTML PDF     Appendix B - Library routines

HTML PDF     Appendix C - Context-free grammars and I/O facilities for Parva and C#Minor

HTML PDF     Appendix D - Software resources for this book

HTML PDF     The programming language Parva (Level 1, Chapter 13)

HTML PDF     The programming language Parva (Level 2, Chapter 14)

HTML PDF     The programming language C#Minor

HTML PDF     The GNU General Public Licence

HTML PDF     Bibliography

HTML PDF     Differences between the Linz and extended versions of Coco/R

HTML        Errata in the first printing


The C# software described in this book was originally developed using the SSCLI (Rotor) distribution from Microsoft.

The Java software was originally developed using the JDK from Sun and also the open source Jikes compiler from IBM's DeveloperWorks.


The following papers and reports may also be of interest:

PDF     Coco/R - A Generator for Fast Compiler Front-Ends (Hanspeter Mössenböck, ETH Zürich Technical Report

PDF     LL(1) Conflict Resolution in a Recursive Descent Compiler Generator (Albrecht Wöß, Markus Löberbauer, Hanspeter Mössenböck, 2004)

PDF     Data Structures in Coco/R (Hanspeter Mössenböck, 2004)

PDF     How to Build Abstract Syntax Trees with Coco/R (Hanspeter Mössenböck, 2011)

HTML   Useful links to other resources (Needs revision!)

PDF     Extended Coco/R User Manual (Pat Terry, 2005, following Mössenböck)

HTML PDF     Pitfalls and tips when using Coco/R (Pat Terry, 2021)