the structure and design of programming languages

7
The Structure and Design of Programming Languages JOHN E. NICHOLLS IBM (UK) Laboratories Ltd. W ADDISON-WESLEY PUBLISHING COMPANY Reading, Massachusetts Menlo Park, California London Amsterdam Don Mills, Ontario • Sydney

Upload: others

Post on 03-Jun-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Structure and Design of Programming Languages

The Structure and Design of

Programming Languages

JOHN E. NICHOLLS IBM (UK) Laboratories Ltd.

W ADDISON-WESLEY PUBLISHING COMPANY Reading, Massachusetts • Menlo Park, California London • Amsterdam • Don Mills, Ontario • Sydney

Page 2: The Structure and Design of Programming Languages

Contents

PART 1 INTRODUCTION: BACKGROUND AND TECHNICAL FOUNDATIONS

CHAPTER 1 INTRODUCTION

Bibliography 6

CHAPTER 2 USER ASPECTS

2.1 Introduction 9

2.2 Objectives for Language Design 10

2.3 Users and Their Characteristics 12

2.4 Studies of the Use of Programming Languages 13

2.5 The Programming Process 16

2.6 Structured Programming 17

2.7 The Dialogue Between User and System 18

2.8 Errors in Programming 19

Bibliography 20

XV

Page 3: The Structure and Design of Programming Languages

xvi Contents

CHAPTER 3 APPLICATIONS

3.1 Introduction 27

3.2 Scientific Computing 28

3.3 Commercial Computing 31

3.4 Systems Programming 32

3.5 Combinatorial Programming 34

3.6 Summary 36

Bibliography 36

CHAPTER 4 THE IMPLEMENTATION OF LANGUAGES

4.1 Introduction 39

4.2 Types of Compilers 40

4.3 Outline of Compiler Design 42

4.4 Optimization 46

4.5 Compiler Output 48

4.6 Formal Methods of Compiler Construction 50

4.7 Programming Languages and Machine Design 51

Bibliography 52

CHAPTER 5 THEORETICAL FOUNDATIONS

5.1 Introduction 59

5.2 Algorithms 61

5.3 Basic Mathematics 62

5.4 Formal Systems 64

5.5 Abstract Syntax 69

5.6 Proving Program Correctness 76

5.7 Analysis of Algorithms 78

5.8 Some Results from the Analysis of Algorithms 79

Bibliography 81

Page 4: The Structure and Design of Programming Languages

Contents xvii

PART 2 ELEMENTS OF PROCEDURAL PROGRAMMING LANGUAGES

CHAPTER 6 PROGRAM STRUCTURE AND REPRESENTATION

6.1 Introduction 91

6.2 The Importance of Structure 92

6.3 Fixed- and Free-Format Languages 93

6.4 Comments 94

6.5 A Hierarchy of Program Elements 96

6.6 Program Structure of Some Current Languages 107

6.7 Editing and Processing Program Text 118

6.8 Text-Copying Systems 119

6.9 The COBOL Library Module 120

6.10 Macroprocessors of High-Level Languages 122

6.11 The PL/I Preprocessor Facilities 123

6.12 Segmentation 125

6.13 Segmentation and Programming Languages 127

Bibliography 129

CHAPTER 7 DATA ELEMENTS, VARIABLES, AND DECLARATIONS

7.1 Introduction 137

7.2 Elements and Structures 139

7.3 The Concept of a Variable in Programming Languages 140

7.4 Binding 142

7.5 Type 143

7.6 Other Attributes of Data Elements 145

7.7 Literals and Constants 152

7.8 A Survey of Data Element Types 155

7.9 Numeric Data 156

7.10 Logical Data 159

7.11 Control Variables 161

7.12 Data Elements in Current Languages 162

7.13 PL/I Problem Data 168

Page 5: The Structure and Design of Programming Languages

xviii Contents

7.14 PL/I Control Variables 170

7.15 Declarations 173

7.16 Control of Defaults 178

7.17 Fixed and Variable Types 180

7.18 Further Reading 184

Bibliography 185

Exercises 188

CHAPTER 8 DATA STRUCTURES

8.1 Introduction 191

8.2 Inverse-Access Functions 195

8.3 Data Structures and Storage Structures 195

8.4 Storage Models in High-Level Languages 196

8.5 The Place of Storage Concepts in Programming Languages 206

8.6 Data Structures in Programming Languages 207

8.7 Further Reading 274

Bibliography 278

CHAPTER 9 EXPRESSIONS AND ASSIGNMENT

9.1 Introduction 295

9.2 The History of Arithmetic Operations 297

9.3 Simple Expressions 299

9.4 Arithmetic Operators 300

9.5 Fixed-Point Operators 302

9.6 Fixed-Point Arithmetic in COBOL and PL/I 306

9.7 Other Types of Operator 316

9.8 Conditional Expressions 322

9.9 Array Expressions 325

9.10 Array Operations 326

9.11 Binary Operators Giving Array Results 326

9.12 Unary Operators Giving Array Results 326

9.13 General Operators in APL 329

9.14 General Expressions 332

9.15 Expressions in ALGOL, COBOL, and PL/I 341

9.16 FORTRAN Expressions 341

Page 6: The Structure and Design of Programming Languages

Contents xix

9.17 ALGOL Expressions 342

9.18 COBOL Expressions 342

9.19 PL/I Expressions 344

9.20 Assignment 345

Bibliography 350 Exercises 355

CHAPTER 10 SEQUENCING AND CONTROL STRUCTURES

10.1 Introduction 359

10.2 The GO TO Statement 361

10.3 The IF Statement 372

10.4 The CASE Statement 381

10.5 Decision Tables 382

10.6 Looping Statements 387

10.7 Condition Handling 399

10.8 COBOL Condition Handling 400

10.9 PL/I Condition Handling 401

10.10 A Comparison of Status-Condition Handling in COBOL and PL/I . 406

10.11 Asynchronous Processing 406

10.12 Further Reading 408

Bibliography 410

Exercises 416

CHAPTER 11 BASIC INPUT-OUTPUT

11.1 Introduction 419

11.2 Files 422

11.3 Blocks, Records, and Fields 424

11.4 Data Set Labels 426

11.5 Data Set Organization 426

11.6 File Concepts in COBOL and PL/I 428

11.7 Two Forms of Sequential Input-Output: Stream and Record 439

11.8 The READ and WRITE Statements 442

11.9 Data Transmission in Record I/O 443

11.10 Input-Output Conditions and Errors 447

11.11 Updating a Master File 450

Page 7: The Structure and Design of Programming Languages

xx Contents

11.12 Summary—The Importance of Sequential Processing 453

11.13 Stream Input-Output 453

11.14 Specification of the Data List 457

11.15 Formatless I/O 464

11.16 PL/I List-Directed I/O 465

11.17 I/O with Self-Identifying Data (Data-Directed I/O) 466

11.18 Stream I/O for Internal Transmission 469

11.19 Report Writing 470

Bibliography 475

Exercises 482

CHAPTER 12 SUBROUTINES, PROCEDURES, AND PROGRAMS

12.1 Introduction 485

12.2 Subroutine and Function Procedures 487

12.3 The Static Structure of Procedures: The Syntax of Procedure Specification 488

12.4 Examples of Procedure Syntax 494

12.5 The Dynamic Structure of Procedures: The Semantics of

Procedure Invocation 498

12.6 Call by Name, Call by Value, and Call by Reference 499

12.7 Further Topics 505

12.8 Summary: Aspects of Procedure Design 521

Bibliography 529

Exercises 533

APPENDIX 537

INDEX 561