Language Structures and Compilers
In this chapter we are aiming at developing a compiler (translator) for a simple, rudimentary programming language. This compiler program may serve as an example for the systematic, well-structured development of a program of non-trivial complexity and size. In this respect, it constitutes a welcome application of the program and data structuring disciplines exposed and elaborated in the preceding chapters, but in addition to this, the aim is to present a general introduction to the structure and operation of compilers. Knowledge and insight on this subject will both enhance the general understanding of the art of programming in terms of high-level languages and will make it easier for a programmer to develop his own systems appropriate for specific purposes and areas of application. Since it is well recognized that the discipline of compiler engineering is a complicated and wide subject, the chapter’s character in this latter respect will necessarily be introductory and expository. Perhaps the most important single point is that the structure of language is mirrored in the structure of its compiler and that its complexity—or simplicity—intimately determines the complexity of its compiler. We shall therefore start by describing language composition and will then concentrate exclusively on simple structures that lead to simple, modular translators. Language constructs of this kind of structural simplicity are, as it turns out, adequate for virtually all genuine needs arising in practical programming languages.
- 5.1Language Definition and Structure
- 5.2Sentence Analysis
- 5.3Constructing a Syntax Graph
- 5.4Constructing a Parser for a Given Syntax
- 5.5Constructing a Table-Driven Parsing Program
- 5.6A Translator from BNF into Parser-Driving Data Structures
- 5.7The Programming Language PL/0
- 5.8A Parser for PL/0
- 5.9Recovering from Syntactic Errors
- 5.10A PL/0 Processor
- 5.11Code Generation
- ❧Exercises
- ❧References