Preface PDF
Preface PDF
Preface PDF
This text developed out of our experiences teaching courses covering the
formal semantics of programming languages. Independently we both developed laboratory exercises implementing small programming languages in
Prolog following denotational definitions. Prolog proved to be an excellent
tool for illustrating the formal semantics of programming languages. We
found that these laboratory exercises were highly successful in motivating
students since the hands-on experience helped demystify the study of formal semantics. At a professional meeting we became aware of each others
experiences with a laboratory approach to semantics, and this book evolved
from that conference.
Although this text has been carefully written so that the laboratory activities
can be omitted without loss of continuity, we hope that most readers will try
the laboratory approach and experience the same success that we have observed in our classes.
Overall Goals
We have pursued a broad spectrum of definitional techniques, illustrated
with numerous examples. Although the specification methods are formal,
the presentation is gentle, providing just enough in the way of mathematical underpinnings to produce an understanding of the metalanguages. We
hope to supply enough coverage of mathematics and formal methods to justify the definitional techniques, but the text is accessible to students with a
basic grounding in discrete mathematics as presented to undergraduate
computer science students.
There has been a tendency in the area of formal semantics to create cryptic,
overly concise semantic definitions that intimidate students new to the study
of programming languages. The emphasis in this text is on clear notational
conventions with the goals of readability and understandability foremost in
our minds.
As with other textbooks in this field, we introduce the basic concepts using
mini-languages that are rich enough to illustrate the fundamental concepts,
yet sparse enough to avoid being overwhelming. We have named our minilanguages after birds.
vi
PREFACE
Wren is a simple imperative language with two types, integer and Boolean, thus allowing for context-sensitive type and declaration checking. It
has assignment, if, while, and input/output commands.
Pelican, a block-structured, imperative language, is an extension of Wren
containing the declaration of constants, anonymous blocks, procedures,
and recursive definitions.
The description of continuations in denotational semantics requires a modified version of Wren with goto statements, which we call Gull. This minilanguage can be skipped without loss of continuity if continuations are not
covered.
10
11
12
13
PREFACE
vii
Overview
The first four chapters deal primarily with the syntax of programming languages. Chapter 1 treats context-free syntax in the guise of BNF grammars
and their variants. Since most methods of semantic specification use abstract syntax trees, the abstract syntax of languages is presented and contrasted with concrete syntax.
Language processing with Prolog is introduced in Chapter 2 by describing a
scanner for Wren and a parser defined in terms of Prolog logic grammars.
These utilities act as the front end for the prototype context checkers, interpreters, and translators developed later in the text. Extensions of BNF grammars that provide methods of verifying the context-sensitive aspects of programming languagesnamely, attribute grammars and two-level grammars
are described in Chapters 3 and 4.
Chapters 5 through 8 are devoted to semantic formalisms that can be classified as operational semantics. Chapter 5 introduces the lambda calculus
by describing its syntax and the evaluation of lambda expressions by reduction rules. Metacircular interpreters are consider in Chapter 6, which introduces the self-definition of programming languages.
Chapter 7 describes the translation of Wren into assembly language using
an attribute grammar that constructs the target code as a program is parsed.
Two well-known operational formalisms are treated in Chapter 8: the SECD
machinean abstract machine for evaluating the lambda calculusand
structural operational semanticsan operational methodology for describing the semantics of programming languages in terms of logical rules of
inference. We use this technique to specify the semantics of Wren formally.
The last five chapters present three traditional methods of defining the semantics of programming languages formally and one recently proposed technique. Denotational semantics, one of the most complete and successful
methods of specifying a programming language, is covered in Chapter 9.
Specifications of several languages are provided, including a calculator language, Wren, Pelican, and Gull, a language whose semantics requires continuation semantics. Denotational semantics is also used to check the context constraints for Wren. Chapter 10 deals with the mathematical foundations of denotational semantics in domain theory by describing the data
structures employed by denotational definitions. Chapter 10 also includes a
justification for recursive definitions via fixed-point semantics, which is then
applied in lambda calculus evaluation.
viii
PREFACE
PREFACE
ix
An appendix covering the basics of Prolog is provided for students unfamiliar with logic programming.
Our experience has shown that the laboratory practice greatly enhances the
learning experience. The only way to master formal methods of language
definition is to practice writing and reading language specifications. We involve students in the implementation of general tools that can be applied to
a variety of examples and that provide increased motivation and feedback to
the students. Submitting specifications to a prototyping system can uncover oversights and subtleties that are not apparent to a casual reader. As
authors, we have frequently used these laboratory approaches to help debug our formal specifications!
Laboratory materials found in this textbook are available on the Internet via
anonymous ftp from ftp.cs.uiowa.edu in the subdirectory pub/slonnegr.
Laboratory Activities
Chapter 2:
Chapter 3:
Chapter 4:
Chapter 5:
Chapter 6:
Chapter 7:
Chapter 8:
Chapter 9:
PREFACE
Acknowledgments
We would like to thank Addison-Wesley for their support in developing this
textin particular, Tom Stone, senior editor for Computer Science, Kathleen
Billus, assistant editor, Marybeth Mooney, production coordinator, and the
many other people who helped put this text together.
We would like to acknowledge the following reviewers for their valuable feedback that helped us improve the text: Doris Carver (Louisiana State University), Art Fleck (University of Iowa), Ray Ford (University of Montana), Phokion
Kolaitis (Santa Cruz), William Purdy (Syracuse University), and Roy Rubinstein
(Worcester Polytech). The comments and suggestions of a number of students contributed substantially to the text; those students include Matt Clay,
David Frank, Sun Kim, Kent Lee, Terry Letsche, Sandeep Pal, Ruth Ruei,
Matt Tucker, and Satish Viswanantham.
We used Microsoft Word and Aldus PageMaker for the Macintosh to develop
this text. We owe a particular debt to the Internet, which allowed us to exchange and develop materials smoothly. Finally, we each would like to thank
our respective family members whose encouragement and patience made
this text possible.
Ken Slonneger
Barry L. Kurtz