Programming Language Design Concepts 1st Edition Findlay download
Programming Language Design Concepts 1st Edition Findlay download
Findlay download
https://ebookname.com/product/programming-language-design-
concepts-1st-edition-findlay/
https://ebookname.com/product/java-programming-exercises-volume-
one-language-fundamentals-and-core-concepts-1st-edition-
christian-ullenboom/
https://ebookname.com/product/programming-language-
foundations-1st-edition-aaron-stump/
https://ebookname.com/product/mips-assembly-language-programming-
robert-britton/
https://ebookname.com/product/renin-angiotensin-system-and-
cardiovascular-disease-1st-edition-walmor-c-demello-md/
Computer Viruses For Dummies Peter H. Gregory
https://ebookname.com/product/computer-viruses-for-dummies-peter-
h-gregory/
https://ebookname.com/product/agrip-af-noregskonungas%c7%abgum-a-
twelfth-century-synoptic-history-of-the-kings-of-norway-2nd-
revised-edition-matthew-james-driscoll/
https://ebookname.com/product/buddhist-public-advocacy-and-
activism-in-thailand-a-rhetoric-of-dignity-and-duty-2024th-
edition-craig-m-pinkerton/
https://ebookname.com/product/critical-companion-to-t-s-eliot-a-
literary-reference-to-his-life-and-work-1st-edition-russell-
elliott-murphy/
Atoms and materials 1st Edition Kyle
https://ebookname.com/product/atoms-and-materials-1st-edition-
kyle/
PROGRAMMING LANGUAGE
DESIGN CONCEPTS
PROGRAMMING LANGUAGE
DESIGN CONCEPTS
All Rights Reserved. No part of this publication may be reproduced, stored in a retrieval system or transmitted in
any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except under
the terms of the Copyright, Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright
Licensing Agency Ltd, 90 Tottenham Court Road, London W1T 4LP, UK, without the permission in writing of the
Publisher, with the exception of any material supplied specifically for the purpose of being entered and executed
on a computer system for exclusive use by the purchase of the publication. Requests to the Publisher should be
addressed to the Permissions Department, John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West
Sussex PO19 8SQ, England, or emailed to [email protected], or faxed to (+44) 1243 770620.
This publication is designed to provide accurate and authoritative information in regard to the subject matter
covered. It is sold on the understanding that the Publisher is not engaged in rendering professional services. If
professional advice or other expert assistance is required, the services of a competent professional should be sought.
John Wiley & Sons Inc., 111 River Street, Hoboken, NJ 07030, USA
John Wiley & Sons Australia Ltd, 33 Park Road, Milton, Queensland 4064, Australia
John Wiley & Sons (Asia) Pte Ltd, 2 Clementi Loop #02-01, Jin Xing Distripark, Singapore 129809
John Wiley & Sons Canada Ltd, 22 Worcester Road, Etobicoke, Ontario, Canada M9W 1L1
Wiley also publishes its books in a variety of electronic formats. Some content that appears
in print may not be available in electronic books.
A catalogue record for this book is available from the British Library
ISBN 0-470-85320-4
Preface xv
Part I: Introduction 1
1 Programming languages 3
1.1 Programming linguistics 3
1.1.1 Concepts and paradigms 3
1.1.2 Syntax, semantics, and pragmatics 5
1.1.3 Language processors 6
1.2 Historical development 6
Summary 10
Further reading 10
Exercises 10
vii
viii Contents
10 Concurrency 231
10.1 Why concurrency? 231
10.2 Programs and processes 233
10.3 Problems with concurrency 234
10.3.1 Nondeterminism 234
10.3.2 Speed dependence 234
10.3.3 Deadlock 236
10.3.4 Starvation 237
10.4 Process interactions 238
10.4.1 Independent processes 238
10.4.2 Competing processes 238
10.4.3 Communicating processes 239
10.5 Concurrency primitives 240
10.5.1 Process creation and control 241
10.5.2 Interrupts 243
10.5.3 Spin locks and wait-free algorithms 243
10.5.4 Events 248
10.5.5 Semaphores 249
10.5.6 Messages 251
10.5.7 Remote procedure calls 252
10.6 Concurrent control abstractions 253
10.6.1 Conditional critical regions 253
10.6.2 Monitors 255
10.6.3 Rendezvous 256
Summary 258
Further reading 258
Exercises 259
Summary 328
Further reading 328
Exercises 329
The first programming language I ever learned was ALGOL60. This language was
notable for its elegance and its regularity; for all its imperfections, it stood head and
shoulders above its contemporaries. My interest in languages was awakened, and
I began to perceive the benefits of simplicity and consistency in language design.
Since then I have learned and programmed in about a dozen other languages,
and I have struck a nodding acquaintance with many more. Like many pro-
grammers, I have found that certain languages make programming distasteful, a
drudgery; others make programming enjoyable, even esthetically pleasing. A good
language, like a good mathematical notation, helps us to formulate and communi-
cate ideas clearly. My personal favorites have been PASCAL, ADA, ML, and JAVA.
Each of these languages has sharpened my understanding of what programming
is (or should be) all about. PASCAL taught me structured programming and data
types. ADA taught me data abstraction, exception handling, and large-scale pro-
gramming. ML taught me functional programming and parametric polymorphism.
JAVA taught me object-oriented programming and inclusion polymorphism. I had
previously met all of these concepts, and understood them in principle, but I did
not truly understand them until I had the opportunity to program in languages
that exposed them clearly.
Contents
This book consists of five parts.
Chapter 1 introduces the book with an overview of programming linguistics
(the study of programming languages) and a brief history of programming and
scripting languages.
Chapters 2–5 explain the basic concepts that underlie almost all programming
languages: values and types, variables and storage, bindings and scope, procedures
and parameters. The emphasis in these chapters is on identifying the basic
concepts and studying them individually. These basic concepts are found in almost
all languages.
Chapters 6–10 continue this theme by examining some more advanced con-
cepts: data abstraction (packages, abstract types, and classes), generic abstraction
(or templates), type systems (inclusion polymorphism, parametric polymor-
phism, overloading, and type conversions), sequencers (including exceptions), and
concurrency (primitives, conditional critical regions, monitors, and rendezvous).
These more advanced concepts are found in the more modern languages.
Chapters 11–16 survey the most important programming paradigms, compar-
ing and contrasting the long-established paradigm of imperative programming
with the increasingly important paradigms of object-oriented and concurrent pro-
gramming, the more specialized paradigms of functional and logic programming,
and the paradigm of scripting. These different paradigms are based on different
xv
xvi Preface
selections of key concepts, and give rise to sharply contrasting styles of language
and of programming. Each chapter identifies the key concepts of the subject
paradigm, and presents an overview of one or more major languages, showing
how concepts were selected and combined when the language was designed.
Several designs and implementations of a simple spellchecker are presented to
illustrate the pragmatics of programming in all of the major languages.
Chapters 17 and 18 conclude the book by looking at two issues: how to select
a suitable language for a software development project, and how to design a
new language.
The book need not be read sequentially. Chapters 1–5 should certainly be
read first, but the remaining chapters could be read in many different orders.
Chapters 11–15 are largely self-contained; my recommendation is to read at least
some of them after Chapters 1–5, in order to gain some insight into how major
languages have been designed. Figure P.1 summarizes the dependencies between
the chapters.
1
Introduction
2 3 4 5
Values and Variables and Bindings and Procedural
Types Storage Scope Abstraction
6 7 8 9 10
Data Generic Type Control Concurrency
Abstraction Abstraction Systems Flow
11 12 13 14 15 16
Imperative OO Concurrent Functional Logic Scripting
Programming Programming Programming Programming Programming
17 18
Language Language
Selection Design
Exercises
Each chapter is followed by a number of relevant exercises. These vary from
short exercises, through longer ones (marked *), up to truly demanding ones
(marked **) that could be treated as projects.
A typical exercise is to analyze some aspect of a favorite language, in the
same way that various languages are analyzed in the text. Exercises like this are
designed to deepen readers’ understanding of languages that they already know,
and to reinforce understanding of particular concepts by studying how they are
supported by different languages.
A typical project is to design some extension or modification to an existing
language. I should emphasize that language design should not be undertaken
lightly! These projects are aimed particularly at the most ambitious readers, but
all readers would benefit by at least thinking about the issues raised.
Readership
All programmers, not just language specialists, need a thorough understanding
of language concepts. This is because programming languages are our most
fundamental tools. They influence the very way we think about software design
and implementation, about algorithms and data structures.
This book is aimed at junior, senior, and graduate students of computer
science and information technology, all of whom need some understanding of
the fundamentals of programming languages. The book should also be of inter-
est to professional software engineers, especially project leaders responsible
for language evaluation and selection, designers and implementers of language
processors, and designers of new languages and of extensions to existing languages.
To derive maximum benefit from this book, the reader should be able to
program in at least two contrasting high-level languages. Language concepts can
best be understood by comparing how they are supported by different languages. A
reader who knows only a language like C, C++, or JAVA should learn a contrasting
language such as ADA (or vice versa) at the same time as studying this book.
The reader will also need to be comfortable with some elementary concepts
from discrete mathematics – sets, functions, relations, and predicate logic – as
these are used to explain a variety of language concepts. The relevant mathematical
concepts are briefly reviewed in Chapters 2 and 15, in order to keep this book
reasonably self-contained.
This book attempts to cover all the most important aspects of a large subject.
Where necessary, depth has been sacrificed for breadth. Thus the really serious
xviii Preface
student will need to follow up with more advanced studies. The book has an
extensive bibliography, and each chapter closes with suggestions for further
reading on the topics covered by the chapter.
Acknowledgments
Bob Tennent’s classic book Programming Language Principles has profoundly
influenced the way I have organized this book. Many books on programming
languages have tended to be syntax-oriented, examining several popular languages
feature by feature, without offering much insight into the underlying concepts
or how future languages might be designed. Some books are implementation-
oriented, attempting to explain concepts by showing how they are implemented
on computers. By contrast, Tennent’s book is semantics-oriented, first identifying
and explaining powerful and general semantic concepts, and only then analyzing
particular languages in terms of these concepts. In this book I have adopted Ten-
nent’s semantics-oriented approach, but placing far more emphasis on concepts
that have become more prominent in the intervening two decades.
I have also been strongly influenced, in many different ways, by the work
of Malcolm Atkinson, Peter Buneman, Luca Cardelli, Frank DeRemer, Edsger
Dijkstra, Tony Hoare, Jean Ichbiah, John Hughes, Mehdi Jazayeri, Bill Joy, Robin
Milner, Peter Mosses, Simon Peyton Jones, Phil Wadler, and Niklaus Wirth.
I wish to thank Bill Findlay for the two chapters (Chapters 10 and 13) he has
contributed to this book. His expertise on concurrent programming has made this
book broader in scope than I could have made it myself. His numerous suggestions
for my own chapters have been challenging and insightful.
Last but not least, I would like to thank the Wiley reviewers for their
constructive criticisms, and to acknowledge the assistance of the Wiley editorial
staff led by Gaynor Redvers-Mutton.
David A. Watt
Brisbane
March 2004
PART I
INTRODUCTION
1
Chapter 1
Programming languages
3
4 Chapter 1 Programming languages
Just as important as the individual concepts are the ways in which they may
be put together to design complete programming languages. Different selections
of key concepts support radically different styles of programming, which are
called paradigms. There are six major paradigms. Imperative programming is
characterized by the use of variables, commands, and procedures; object-oriented
programming by the use of objects, classes, and inheritance; concurrent pro-
gramming by the use of concurrent processes, and various control abstractions;
functional programming by the use of functions; logic programming by the use of
relations; and scripting languages by the presence of very high-level features. We
shall study all of these paradigms in Part IV of this book.
PART III
MAY
II
May stopped to speak to the hired girl as she went out, and was
alarmed by the creeping dusk already in the inn. She breathed again
when she was in the road, and saw the dull light holding yet on
either hand. The soft closing of the door behind her back gave her a
long-forgotten thrill, bringing back similar autumn evening hours,
when she had gone to meet a lover from over the sands.
She got down to the shore about the time that the scene at
Blindbeck was drawing to an end. She hurried, not only because she
had little or no time to waste, but because she could not have gone
slowly if she had tried. The young May had never gone slowly, who
was all kindness and knew nothing of pride. She ran down the
shingle and across the sand, only pausing to draw breath and to
reprove herself at the channel's edge. Passers-by on the flat road
stopped to stare at her as she sped across, wondering what she
could be doing at that hour. Pausing, she looked across at the farm
before she bent to the boat, chiding herself for her almost childish
haste. But her tongue ached to let loose the words of persuasion
that she carried with her, and her heart ached for the word of
permission that she was sure she would carry back. She did not
doubt for a moment that Sarah would give way, so strong was her
inward belief that Geordie was coming home.
At last she pushed off, stepped in and punted herself across,
and once out again on dry ground tried to hold herself to a walk.
The sand, ribbed and hard beneath her feet, spoke to the fact that
the tide had been gone for hours. It was extraordinary how
forgotten the sands always seemed as soon as the tide had gone
away. Only those who had proved it by daily experience could
believe that the water would ever return. Even to them it remained
something of the miracle that it was in truth, arousing continually a
thrill of awed surprise. Yet, side by side with that impression of final
retreat, of waste that had always been waste and would never be
reclaimed, was one of a brooding terror that was only waiting its
hour. The sea and the sands were like cat and mouse, May thought,-
-the one, aloof, indifferent, yet always poised to leap; the other,
inert, paralysed though apparently free, and always the certain
victim in the end.
She looked behind and before from the quiet home which she
had left to the still more lonely and quiet house which was her goal.
There was a point about half-way across at which it seemed as if she
would never reach the one, never get back to the other in all time.
Both seemed to recede from her equally as she moved, vague
shapes formed only of imagination and the mist. Just for a moment
that vagueness of things which she knew to be concrete caught her
by the throat. The little that she could see of the earth was so
cloudlike, so lacking in sturdy strength. The very shore of the marsh
looked as though a breath might dissolve it in thin air. Though the
distance across was little more than a mile, the feeling of space
around her was infinite as the sky. The sands seemed suddenly to
become a treadmill under her feet, turning and turning, but never
bringing her to the horizon which she sought. The whole doorway of
the bay was blocked by the great wall of mist, and over the Lake
mountains there was a smother of mist, and mist over all the land
that went east to the Pennine range. She began to fear even the
crinkled sand which felt so firm, as if it might suddenly sway and
shift like one of the many traps with which the bay was sown.
Behind her, the grey, faint-gleaming strip of the channel seemed to
cut her off from her safe home. A slice of the bank broke suddenly
with an echoing spash, chilling her with the lonely terror of water
that has a victim in its hold. The boat, helpless-looking, inert, a mere
black speck on the channel edge, seemed the only insoluble thing
beside herself. She longed for the comfort of her feet on the tarred
boards, for the reassurance of her hands against the sculls. It was a
moment or two before she had the courage to let it go, and face a
world that was full of bodiless shapes and evanescent shores.
But almost before she knew it she was on the opposite side,
scrambling up the stones to the grassy slope beyond, and so,
panting and hurrying, to the top of the sea-wall. She saw at once
that there was nobody in the house, that it was still with the growing
stillness of augmented hours, and a further chill fell on her happy
mood. Yet she was glad at least to be there to welcome the old folks
when they came, and in any case they could not be very far. Every
jolt of the trap must be bringing them nearer to the net which she
was spreading so lovingly for their feet. They would be tired, of
course, and probably very cross, but May was used to market-day
moods and would not care. With affectionate ruthlessness she told
herself that would yield to her all the sooner for being tired.
Presently they would agree unwillingly that she might have her way,
and then she would hurry home again as if on wings. They would be
crosser than ever after she had gone, vexed both with her and
themselves and terribly touched in their pride. And then, slowly but
surely, the hope that she had forced upon them would begin to race
its stimulant through their veins. They would lie down to sleep with
a secret gladness that they had not the courage to confess, and
would wake in the morning and know that the world had been made
for them anew.
She kept stopping the rush of her thoughts to send her senses
over the marsh, but no sign of life came back to her, or sound of
wheel or hoof. The wide stretches of grass and plough and the long
length of road seemed almost as unsuggestive of human influence
as the sands themselves. Swifter and swifter faded the passionate
confidence which had sent her out, leaving the risks of the matter
uppermost in her mind. She remembered that it was possible to be
patient all one's life, and yet to wreck the fruits of it in an unguarded
hour. This sudden mental and physical rashness might be symbolical
of a greater rashness of the soul. Perhaps after to-night all her
footholds and anchorages might go, leaving the world that she had
managed so bravely only a nightmare blurred by tears.
The dusk thickened about her as the night tried to impress itself
on the earth as a separate entity from the mist. The most that it
could do, however, was to produce the effect of a hovering shadow
from some huge arrested wing. The real warning of night was in the
deepened sense of loneliness and dread of personal diminution in a
growing space, in the further recession of things unseen as well as
seen. It lay, too, in the stirring consciousness of the impending
advent of the tide. She began to look anxiously towards her father's
window for the lamp, and though she was comforted when she saw
no sign, it stamped the illusion of desolation on her mind. Then she
heard the cattle stir in the shippon as she walked along the wall, and
was cheered and companioned by them for a little while. She would
have gone down to them, or to the dog, who was always a firm
friend, but she was afraid of losing her consciousness of time. She
could not tear herself, either, from her breathless waiting for the
silence to fill with life. She was cold whether she stood or walked,
and more and more oppressed by a sense of folly and grave doubt.
She even laughed at the middle-aged woman who had thrilled like a
girl, but she laughed between her tears. Once or twice she ran down
the bank and on to the sand, but always something drew her back,
and at last, when she had listened so long that she had ceased to
hear, there came the crunching sound of the Thornthwaite wheels. It
was there suddenly where there had been no sign, as if it had only
begun at the moment it reached her ear. At once her courage sprang
up again, and her spirits rose. The whole affair was sweet and brave
once more. It was as if she had heard her lover himself coming
surely towards her over the lonely marsh....
III
PART IV
GEORDIE-AN'-JIM
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com