Compiling with C# and Java - abridged online copy (2017/2021)

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 Classes of translator
2.2 T-diagrams
2.3 Self-resident compilers, cross compilers and self-compiling compilers.
2.4 Linkers and loaders
2.5 Phases in translation
2.6 Multi-stage translators
2.7 Interpreters, interpretive compilers and emulators
2.8 The P-system and the JVM
2.9 JIT compilers and the .NET Framework

HTML PDF     Chapter 3 - Compiler Development and Bootstrapping

3.1 Using a high-level language to develop a compiler for a new high-level language
3.2 Using a high-level language to develop a two-stage compiler for a new language
3.3 Bootstrapping
3.4 Self-compiling compilers
3.5 The half bootstrap - porting a compiler to a different machine
3.6 Bootstrapping from a portable interpretive compiler
3.7 A P-code assembler
3.8 The use of compiler generating tools
3.9 Diagrams for some case studies

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

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 Restrictions on grammars defined using EBNF notation
7.4 Language design and the consequences of the LL(1) conditions
7.5 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

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

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 Overall form of a Cocol description
10.4 Scanner specification
10.5 Parser specification
10.6 The driver program

HTML PDF     Chapter 11 - Coco/R - A Simple Assembler for the PVM

11.1 Case study - A simple assembler for the PVM

HTML PDF     Chapter 11 - Coco/R - Case Studies (from the 2005 Edition)

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

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

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

14.1 Void functions
14.2 Constraint analysis
14.3 Run-time storage management
14.4 A complete compiler for a set of void functions
14.5 Globally accessible constants and variables
14.6 Value-returning (non-void) functions
14.7 Mutually recursive functions

HTML PDF     Appendix B - Library routines

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

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

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

HTML PDF     The GNU General Public Licence

HTML PDF     Bibliography

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

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)