
- •New to the Tenth Edition
- •Preface
- •Acknowledgments
- •About the Author
- •Contents
- •1.1 Reasons for Studying Concepts of Programming Languages
- •1.2 Programming Domains
- •1.3 Language Evaluation Criteria
- •1.4 Influences on Language Design
- •1.5 Language Categories
- •1.6 Language Design Trade-Offs
- •1.7 Implementation Methods
- •1.8 Programming Environments
- •Summary
- •Problem Set
- •2.1 Zuse’s Plankalkül
- •2.2 Pseudocodes
- •2.3 The IBM 704 and Fortran
- •2.4 Functional Programming: LISP
- •2.5 The First Step Toward Sophistication: ALGOL 60
- •2.6 Computerizing Business Records: COBOL
- •2.7 The Beginnings of Timesharing: BASIC
- •2.8 Everything for Everybody: PL/I
- •2.9 Two Early Dynamic Languages: APL and SNOBOL
- •2.10 The Beginnings of Data Abstraction: SIMULA 67
- •2.11 Orthogonal Design: ALGOL 68
- •2.12 Some Early Descendants of the ALGOLs
- •2.13 Programming Based on Logic: Prolog
- •2.14 History’s Largest Design Effort: Ada
- •2.15 Object-Oriented Programming: Smalltalk
- •2.16 Combining Imperative and Object-Oriented Features: C++
- •2.17 An Imperative-Based Object-Oriented Language: Java
- •2.18 Scripting Languages
- •2.19 The Flagship .NET Language: C#
- •2.20 Markup/Programming Hybrid Languages
- •Review Questions
- •Problem Set
- •Programming Exercises
- •3.1 Introduction
- •3.2 The General Problem of Describing Syntax
- •3.3 Formal Methods of Describing Syntax
- •3.4 Attribute Grammars
- •3.5 Describing the Meanings of Programs: Dynamic Semantics
- •Bibliographic Notes
- •Problem Set
- •4.1 Introduction
- •4.2 Lexical Analysis
- •4.3 The Parsing Problem
- •4.4 Recursive-Descent Parsing
- •4.5 Bottom-Up Parsing
- •Summary
- •Review Questions
- •Programming Exercises
- •5.1 Introduction
- •5.2 Names
- •5.3 Variables
- •5.4 The Concept of Binding
- •5.5 Scope
- •5.6 Scope and Lifetime
- •5.7 Referencing Environments
- •5.8 Named Constants
- •Review Questions
- •6.1 Introduction
- •6.2 Primitive Data Types
- •6.3 Character String Types
- •6.4 User-Defined Ordinal Types
- •6.5 Array Types
- •6.6 Associative Arrays
- •6.7 Record Types
- •6.8 Tuple Types
- •6.9 List Types
- •6.10 Union Types
- •6.11 Pointer and Reference Types
- •6.12 Type Checking
- •6.13 Strong Typing
- •6.14 Type Equivalence
- •6.15 Theory and Data Types
- •Bibliographic Notes
- •Programming Exercises
- •7.1 Introduction
- •7.2 Arithmetic Expressions
- •7.3 Overloaded Operators
- •7.4 Type Conversions
- •7.5 Relational and Boolean Expressions
- •7.6 Short-Circuit Evaluation
- •7.7 Assignment Statements
- •7.8 Mixed-Mode Assignment
- •Summary
- •Problem Set
- •Programming Exercises
- •8.1 Introduction
- •8.2 Selection Statements
- •8.3 Iterative Statements
- •8.4 Unconditional Branching
- •8.5 Guarded Commands
- •8.6 Conclusions
- •Programming Exercises
- •9.1 Introduction
- •9.2 Fundamentals of Subprograms
- •9.3 Design Issues for Subprograms
- •9.4 Local Referencing Environments
- •9.5 Parameter-Passing Methods
- •9.6 Parameters That Are Subprograms
- •9.7 Calling Subprograms Indirectly
- •9.8 Overloaded Subprograms
- •9.9 Generic Subprograms
- •9.10 Design Issues for Functions
- •9.11 User-Defined Overloaded Operators
- •9.12 Closures
- •9.13 Coroutines
- •Summary
- •Programming Exercises
- •10.1 The General Semantics of Calls and Returns
- •10.2 Implementing “Simple” Subprograms
- •10.3 Implementing Subprograms with Stack-Dynamic Local Variables
- •10.4 Nested Subprograms
- •10.5 Blocks
- •10.6 Implementing Dynamic Scoping
- •Problem Set
- •Programming Exercises
- •11.1 The Concept of Abstraction
- •11.2 Introduction to Data Abstraction
- •11.3 Design Issues for Abstract Data Types
- •11.4 Language Examples
- •11.5 Parameterized Abstract Data Types
- •11.6 Encapsulation Constructs
- •11.7 Naming Encapsulations
- •Summary
- •Review Questions
- •Programming Exercises
- •12.1 Introduction
- •12.2 Object-Oriented Programming
- •12.3 Design Issues for Object-Oriented Languages
- •12.4 Support for Object-Oriented Programming in Smalltalk
- •12.5 Support for Object-Oriented Programming in C++
- •12.6 Support for Object-Oriented Programming in Objective-C
- •12.7 Support for Object-Oriented Programming in Java
- •12.8 Support for Object-Oriented Programming in C#
- •12.9 Support for Object-Oriented Programming in Ada 95
- •12.10 Support for Object-Oriented Programming in Ruby
- •12.11 Implementation of Object-Oriented Constructs
- •Summary
- •Programming Exercises
- •13.1 Introduction
- •13.2 Introduction to Subprogram-Level Concurrency
- •13.3 Semaphores
- •13.4 Monitors
- •13.5 Message Passing
- •13.6 Ada Support for Concurrency
- •13.7 Java Threads
- •13.8 C# Threads
- •13.9 Concurrency in Functional Languages
- •13.10 Statement-Level Concurrency
- •Summary
- •Review Questions
- •Problem Set
- •14.1 Introduction to Exception Handling
- •14.2 Exception Handling in Ada
- •14.3 Exception Handling in C++
- •14.4 Exception Handling in Java
- •14.5 Introduction to Event Handling
- •14.6 Event Handling with Java
- •14.7 Event Handling in C#
- •Review Questions
- •Problem Set
- •15.1 Introduction
- •15.2 Mathematical Functions
- •15.3 Fundamentals of Functional Programming Languages
- •15.4 The First Functional Programming Language: LISP
- •15.5 An Introduction to Scheme
- •15.6 Common LISP
- •15.8 Haskell
- •15.10 Support for Functional Programming in Primarily Imperative Languages
- •15.11 A Comparison of Functional and Imperative Languages
- •Review Questions
- •Problem Set
- •16.1 Introduction
- •16.2 A Brief Introduction to Predicate Calculus
- •16.3 Predicate Calculus and Proving Theorems
- •16.4 An Overview of Logic Programming
- •16.5 The Origins of Prolog
- •16.6 The Basic Elements of Prolog
- •16.7 Deficiencies of Prolog
- •16.8 Applications of Logic Programming
- •Review Questions
- •Programming Exercises
- •Bibliography
- •Index

Review Questions |
665 |
An event is a notification that something has occurred that requires special processing. Events are often created by user interactions with a program through a graphical user interface. Java event handlers are called through event listeners. An event listener must be registered for an event if it is to be notified when the event occurs. Two of the most commonly used event listeners interfaces are actionPerformed and itemStateChanged.
Windows Forms is the original approach to building GUI components and handling events in .NET languages. A C# application builds a GUI in this approach by subclassing the Form class. All .NET event handlers use the same protocol. Event handlers are registered by creating an EventHandler object and assigning it to the predefined delegate associated with the GUI object that can raise the event.
B I B L I O G R A P H I C N O T E S
One of the most important papers on exception handling that is not connected with a particular programming language is the work by Goodenough (1975). The problems with the PL/I design for exception handling are covered in MacLaren (1977). The CLU exception-handling design is clearly described by Liskov and Snyder (1979). Exception-handling facilities of the Ada language are described in ARM (1995) and are critically evaluated in Romanovsky and Sandén (2001). Exception handling in C++ is described by Stroustrup (1997). Exception handling in Java is described by Campione et al. (2001).
R E V I E W Q U E S T I O N S
1.Define exception, exception handler, raising an exception, disabling an exception, continuation, finalization, and built-in exception.
2.What are the two alternatives for designing continuation?
3.What are the advantages of having support for exception handling built in to a language?
4.What are the design issues for exception handling?
5.What does it mean for an exception to be bound to an exception handler?
6.What are the possible frames for exceptions in Ada?
7.Where are unhandled exceptions propagated in Ada if raised in a subprogram? A block? A package body? A task?
8.Where does execution continue after an exception is handled in Ada?
9.How can an exception be explicitly raised in Ada?
10.What are the four exceptions defined in the Standard package of Ada?

666Chapter 14 Exception Handling and Event Handling
11.How is a user-defined exception defined in Ada?
12.How can an exception be suppressed in Ada?
13.Describe three problems with Ada’s exception handling.
14.What is the name of all C++ exception handlers?
15.How can exceptions be explicitly raised in C++?
16.How are exceptions bound to handlers in C++?
17.How can an exception handler be written in C++ so that it handles any exception?
18.Where does execution control go when a C++ exception handler has completed its execution?
19.Does C++ include built-in exceptions?
20.Why is the raising of an exception in C++ not called raise?
21.What is the root class of all Java exception classes?
22.What is the parent class of most Java user-defined exception classes?
23.How can an exception handler be written in Java so that it handles any exception?
24.What are the differences between a C++ throw specification and a Java throws clause?
25.What is the difference between checked and unchecked exceptions in Java?
26.How can an exception handler be written in Java so that it handles any exception?
27.Can you disable a Java exception?
28.What is the purpose of the Java finally clause?
29.What advantage do language-defined assertions have over simple if- write constructs?
30.In what ways are exception handling and event handling related?
31.Define event and event handler.
32.What is event-driven programming?
33.What is the purpose of a Java JFrame?
34.What is the purpose of a Java JPanel?
35.What object is often used as the event listener in Java GUI applications?
36.What is the origin of the protocol for an event handler in Java?
37.What method is used to register an event handler in Java?
38.Using .NET’s Windows Forms, what namespace is required to build a GUI for a C# application?
39.How is a component positioned in a form using Windows Forms?
40.What is the protocol of a .NET event handler?
41.What class of object must be created to register a .NET event handler?
42.What role do delegates play in the process of registering event handlers?

Problem Set |
667 |
P R O B L E M S E T
1.What did the designers of C get in return for not requiring subscript range checking?
2.Describe three approaches to exception handling in languages that do not provide direct support for it.
3.From textbooks on the PL/I and Ada programming languages, look up the respective sets of built-in exceptions. Do a comparative evaluation of the two, considering both completeness and flexibility.
4.From ARM (1995), determine how exceptions that take place during rendezvous are handled.
5.From a textbook on COBOL, determine how exception handling is done in COBOL programs.
6.In languages without exception-handling facilities, it is common to have most subprograms include an “error” parameter, which can be set to some value representing “OK” or some other value representing “error in procedure.” What advantage does a linguistic exception-handling facility like that of Ada have over this method?
7.In a language without exception-handling facilities, we could send an error-handling procedure as a parameter to each procedure that can detect errors that must be handled. What disadvantages are there to this method?
8.Compare the methods suggested in Problems 6 and 7. Which do you think is better and why?
9.Write a comparative analysis of the throw clause of C++ and the throws clause of Java.
10.Compare the exception-handling facilities of C++ with those of Ada. Which design, in your opinion, is the most flexible? Which makes it possible to write more reliable programs?
11.Consider the following C++ skeletal program:
class Big { int i;
float f;
void fun1() throw int {
...
try {
...
throw i;
...
throw f;
...
}

668 |
Chapter 14 Exception Handling and Event Handling |
catch(float) { ... }
...
}
}
class Small {
int j;
float g;
void fun2() throw float {
...
try {
...
try {
Big.fun1();
...
throw j;
...
throw g;
...
}
catch(int) { ... }
...
}
catch(float) { ... }
}
}
In each of the four throw statements, where is the exception handled?
Note that fun1 is called from fun2 in class Small.
12.Write a detailed comparison of the exception-handling capabilities of C++ and those of Java.
13.With the help of a book on ML, write a detailed comparison of the exception-handling capabilities of ML and those of Java.
14.Summarize the arguments in favor of the termination and resumption models of continuation.
P R O G R A M M I N G E X E R C I S E S
1.Write an Ada code segment that retries a call to a procedure, Tape_Read, that reads input from a tape drive and can raise the Tape_Read_Error exception.
2.Suppose you are writing a C++ function that has three alternative approaches for accomplishing its requirements. Write a skeletal version of this function so that if the first alternative raises any exception, the

Programming Exercises |
669 |
second is tried, and if the second alternative raises any exception, the third is executed. Write the code as if the three methods were procedures named alt1, alt2, and alt3.
3.Write a Java program that inputs a list of integer values in the range of - 100 to 100 from the keyboard and computes the sum of the squares of the input values. This program must use exception handling to ensure that the input values are in range and are legal integers, to handle the
error of the sum of the squares becoming larger than a standard Integer variable can store, and to detect end-of-file and use it to cause the output of the result. In the case of overflow of the sum, an error message must be printed and the program terminated.
4.Write a C++ program for the specification of Programming Exercise 3.
5.Write an Ada program for the specification of Programming Exercise 3.
6.Revise the Java program of Section 14.4.5 to use EOFException to detect the end of the input.
7.Rewrite the Java code of Section 14.4.6 that uses a finally clause in C++.
This page intentionally left blank

15
Functional Programming
Languages
15.1Introduction
15.2Mathematical Functions
15.3Fundamentals of Functional Programming Languages
15.4The First Functional Programming Language: LISP
15.5An Introduction to Scheme
15.6Common LISP
15.7ML
15.8Haskell
15.9F#
15.10 Support for Functional Programming in Primarily Imperative Languages
15.11 A Comparison of Functional and Imperative Languages
671