Ebook Programing language pragmatics (3rd edition) Part 2

409 583 0
Ebook Programing language pragmatics (3rd edition) Part 2

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

(BQ) Part 2 book Programing language pragmatics has contents: Functional languages, logic languages, concurrency, scripting languages, building a runnable program, run time program management, code improvement.

III Alternative Programming Models As we noted in Chapter 1, programming languages are traditionally though imperfectly classified into various imperative and declarative families We have had occasion in Parts I and II to mention issues of particular importance to each of the major families Moreover much of what we have covered—syntax, semantics, naming, types, abstraction—applies uniformly to all Still, our attention has focused mostly on mainstream imperative languages In Part III we shift this focus Functional and logic languages are the principal nonimperative options We consider them in Chapters 10 and 11, respectively In each case we structure our discussion around a representative language: Scheme for functional programming, Prolog for logic programming In Chapter 10 we also cover eager and lazy evaluation, and first-class and higher-order functions In Chapter 11 we cover issues that make fully automatic, general purpose logic programming difficult, and describe restrictions used in practice to keep the model tractable Optional sections in both chapters consider mathematical foundations: Lambda Calculus for functional programming, Predicate Calculus for logic programming The remaining two chapters consider concurrent and scripting models, both of which are increasingly popular, and cut across the imperative/declarative divide Concurrency is driven by the hardware parallelism of internetworked computers and by the coming explosion in multithreaded processors and chip-level multiprocessors Scripting is driven by the growth of the World Wide Web and by an increasing emphasis on programmer productivity, which places rapid development and reusability above sheer run-time performance Chapter 12 begins with the fundamentals of concurrency, including communication and synchronization, thread creation syntax, and the implementation of threads The remainder of the chapter is divided between shared-memory models, in which threads use explicit or implicit synchronization mechanisms to manage a common set of variables, and messagepassing models, in which threads interact only through explicit communication The first half of Chapter 13 surveys problem domains in which scripting plays a major role: shell (command) languages, text processing and report generation, mathematics and statistics, the “gluing” together of program components, extension mechanisms for complex applications, and client and server-side Web scripting The second half considers some of the more important language innovations championed by scripting languages: flexible scoping and naming conventions, string and pattern manipulation (extended regular expressions), and high level data types This page intentionally left blank 10 Functional Languages Previous chapters of this text have focused largely on imperative programming languages In the current chapter and the next we emphasize functional and logic languages instead While imperative languages are far more widely used, “industrial-strength” implementations exist for both functional and logic languages, and both models have commercially important applications Lisp has traditionally been popular for the manipulation of symbolic data, particularly in the field of artificial intelligence In recent years functional languages—statically typed ones in particular—have become increasingly popular for scientific and business applications as well Logic languages are widely used for formal specifications and theorem proving and, less widely, for many other applications Of course, functional and logic languages have a great deal in common with their imperative cousins Naming and scoping issues arise under every model So types, expressions, and the control-flow concepts of selection and recursion All languages must be scanned, parsed, and analyzed semantically In addition, functional languages make heavy use of subroutines—more so even than most von Neumann languages—and the notions of concurrency and nondeterminacy are as common in functional and logic languages as they are in the imperative case As noted in Chapter 1, the boundaries between language categories tend to be rather fuzzy One can write in a largely functional style in many imperative languages, and many functional languages include imperative features (assignment and iteration) The most common logic language—Prolog—provides certain imperative features as well Finally, it is easy to build a logic programming system in most functional programming languages Because of the overlap between imperative and functional concepts, we have had occasion several times in previous chapters to consider issues of particular importance to functional programming languages Most such languages depend heavily on polymorphism (the implicit parametric kind—Sections 3.5.3 and 7.2.4) Most make heavy use of lists (Section 7.8) Several, historically, were dynamically scoped (Sections 3.3.6 and 3.4.2) All employ recursion (Section 6.6) for repetitive execution, with the result that program behavior and performance depend heavily on the evaluation rules for parameters Programming Language Pragmatics DOI: 10.1016/B978-0-12-374514-9.00021-5 Copyright © 2009 by Elsevier Inc All rights reserved 505 506 Chapter 10 Functional Languages (Section 6.6.2) All have a tendency to generate significant amounts of temporary data, which their implementations reclaim through garbage collection (Section 7.7.3) Our chapter begins with a brief introduction to the historical origins of the imperative, functional, and logic programming models We then enumerate fundamental concepts in functional programming and consider how these are realized in the Scheme dialect of Lisp More briefly, we also consider Caml, Common Lisp, Erlang, Haskell, ML, Miranda, pH, Single Assignment C, and Sisal We pay particular attention to issues of evaluation order and higher-order functions For those with an interest in the theoretical foundations of functional programming, we provide (on the PLP CD) an introduction to functions, sets, and the lambda calculus The formalism helps to clarify the notion of a “pure” functional language, and illuminates the differences between the pure notation and its realization in more practical programming languages 10.1 Historical Origins To understand the differences among programming models, it can be helpful to consider their theoretical roots, all of which predate the development of electronic computers The imperative and functional models grew out of work undertaken by mathematicians Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, and others in the 1930s Working largely independently, these individuals developed several very different formalizations of the notion of an algorithm, or effective procedure, based on automata, symbolic manipulation, recursive function definitions, and combinatorics Over time, these various formalizations were shown to be equally powerful: anything that could be computed in one could be computed in the others This result led Church to conjecture that any intuitively appealing model of computing would be equally powerful as well; this conjecture is known as Church’s thesis Turing’s model of computing was the Turing machine, an automaton reminiscent of a finite or pushdown automaton, but with the ability to access arbitrary cells of an unbounded storage “tape.”1 The Turing machine computes in an imperative way, by changing the values in cells of its tape, just as a high-level imperative program computes by changing the values of variables Church’s model of computing is called the lambda calculus It is based on the notion of parameterized expressions (with each parameter introduced by an occurrence of the Alan Turing (1912–1954), for whom the Turing Award is named, was a British mathematician, philosopher, and computer visionary As intellectual leader of Britain’s cryptanalytic group during World War II, he was instrumental in cracking the German “Enigma” code and turning the tide of the war He also laid the theoretical foundations of modern computer science, conceived the general purpose electronic computer, and pioneered the field of Artificial Intelligence Persecuted as a homosexual after the war, stripped of his security clearance, and sentenced to “treatment” with drugs, he committed suicide 10.2 Functional Programming Concepts 507 letter λ—hence the notation’s name).2 Lambda calculus was the inspiration for functional programming: one uses it to compute by substituting parameters into expressions, just as one computes in a high level functional program by passing arguments to functions The computing models of Kleene and Post are more abstract, and not lend themselves directly to implementation as a programming language The goal of early work in computability was not to understand computers (aside from purely mechanical devices, computers did not exist) but rather to formalize the notion of an effective procedure Over time, this work allowed mathematicians to formalize the distinction between a constructive proof (one that shows how to obtain a mathematical object with some desired property) and a nonconstructive proof (one that merely shows that such an object must exist, perhaps by contradiction, or counting arguments, or reduction to some other theorem whose proof is nonconstructive) In effect, a program can be seen as a constructive proof of the proposition that, given any appropriate inputs, there exist outputs that are related to the inputs in a particular, desired way Euclid’s algorithm, for example, can be thought of as a constructive proof of the proposition that every pair of non-negative integers has a greatest common divisor Logic programming is also intimately tied to the notion of constructive proofs, but at a more abstract level Rather than write a general constructive proof that works for all appropriate inputs, the logic programmer writes a set of axioms that allow the computer to discover a constructive proof for each particular set of inputs We will consider logic programming in more detail in Chapter 11 10.2 Functional Programming Concepts In a strict sense of the term, functional programming defines the outputs of a program as a mathematical function of the inputs, with no notion of internal state, and thus no side effects Among the languages we consider here, Miranda, Haskell, pH, Sisal, and Single Assignment C are purely functional Erlang is nearly so Most others include imperative features To make functional programming practical, functional languages provide a number of features that are often missing in imperative languages, including: First-class function values and higher-order functions Extensive polymorphism Alonzo Church (1903–1995) was a member of the mathematics faculty at Princeton University from 1929 to 1967, and at UCLA from 1967 to 1990 While at Princeton he supervised the doctoral theses of, among many others, Alan Turing, Stephen Kleene, Michael Rabin, and Dana Scott His codiscovery, with Turing, of uncomputable problems was a major breakthrough in understanding the limits of mathematics 508 Chapter 10 Functional Languages List types and operators Structured function returns Constructors (aggregates) for structured objects Garbage collection In Section 3.6.2 we defined a first-class value as one that can be passed as a parameter, returned from a subroutine, or (in a language with side effects) assigned into a variable Under a strict interpretation of the term, first-class status also requires the ability to create (compute) new values at run time In the case of subroutines, this notion of first-class status requires nested lambda expressions that can capture values (with unlimited extent) defined in surrounding scopes Subroutines are second-class values in most imperative languages, but first-class values (in the strict sense of the term) in all functional programming languages A higherorder function takes a function as an argument, or returns a function as a result Polymorphism is important in functional languages because it allows a function to be used on as general a class of arguments as possible As we have seen in Sections 7.1 and 7.2.4, Lisp and its dialects are dynamically typed, and thus inherently polymorphic, while ML and its relatives obtain polymorphism through the mechanism of type inference Lists are important in functional languages because they have a natural recursive definition, and are easily manipulated by operating on their first element and (recursively) the remainder of the list Recursion is important because in the absence of side effects it provides the only means of doing anything repeatedly Several of the items in our list of functional language features (recursion, structured function returns, constructors, garbage collection) can be found in some but not all imperative languages Fortran 77 has no recursion, nor does it allow structured types (i.e., arrays) to be returned from functions Pascal and early versions of Modula-2 allow only simple and pointer types to be returned from functions As we saw in Section 7.1.5, several imperative languages, including Ada, C, and Fortran 90, provide aggregate constructs that allow a structured value to be specified in-line In most imperative languages, however, such constructs are lacking or incomplete C# 3.0 and several scripting languages—Python and Ruby among them—provide aggregates capable of representing an (unnamed) functional value (a lambda expression), but few imperative languages are so expressive A pure functional language must provide completely general aggregates: because there is no way to update existing objects, newly created ones must be initialized “all at once.” Finally, though garbage collection is increasingly common in imperative languages, it is by no means universal, nor does it usually apply to the local variables of subroutines, which are typically allocated in the stack Because of the desire to provide unlimited extent for first-class functions and other objects, functional languages tend to employ a (garbage-collected) heap for all dynamically allocated data (or at least for all data for which the compiler is unable to prove that stack allocation is safe) Because Lisp was the original functional language, and is probably still the most widely used, several characteristics of Lisp are commonly, though inaccurately, 10.3 A Review/Overview of Scheme 509 described as though they pertained to functional programming in general We will examine these characteristics (in the context of Scheme) in Section 10.3 They include: Homogeneity of programs and data: A program in Lisp is itself a list, and can be manipulated with the same mechanisms used to manipulate data Self-definition: The operational semantics of Lisp can be defined elegantly in terms of an interpreter written in Lisp Interaction with the user through a “read-eval-print” loop Many programmers—probably most—who have written significant amounts of software in both imperative and functional styles find the latter more aesthetically appealing Moreover experience with a variety of large commercial projects (see the Bibliographic Notes at the end of the chapter) suggests that the absence of side effects makes functional programs significantly easier to write, debug, and maintain than their imperative counterparts When passed a given set of arguments, a pure function can always be counted on to return the same results Issues of undocumented side effects, misordered updates, and dangling or (in most cases) uninitialized references simply don’t occur At the same time, most implementations of functional languages still fall short in terms of portability, richness of library packages, interfaces to other languages, and debugging and profiling tools We will return to the tradeoffs between functional and imperative programming in Section 10.7 10.3 EXAMPLE 10.1 The read-eval-print loop A Review/Overview of Scheme Most Scheme implementations employ an interpreter that runs a“read-eval-print” loop The interpreter repeatedly reads an expression from standard input (generally typed by the user), evaluates that expression, and prints the resulting value If the user types (+ 4) the interpreter will print If the user types the interpreter will also print 510 Chapter 10 Functional Languages (The number is already fully evaluated.) To save the programmer the need to type an entire program verbatim at the keyboard, most Scheme implementations provide a load function that reads (and evaluates) input from a file: (load "my_Scheme_program") EXAMPLE 10.2 Significance of parentheses As we noted in Section 6.1, Scheme (like all Lisp dialects) uses Cambridge Polish notation for expressions Parentheses indicate a function application (or in some cases the use of a macro) The first expression inside the left parenthesis indicates the function; the remaining expressions are its arguments Suppose the user types ((+ 4)) When it sees the inner set of parentheses, the interpreter will call the function + , passing and as arguments Because of the outer set of parentheses, it will then attempt to call as a zero-argument function—a run-time error: eval: is not a procedure Unlike the situation in almost all other programming languages, extra parentheses change the semantics of Lisp/Scheme programs (+ 4) ((+ 4)) EXAMPLE 10.3 Quoting =⇒ =⇒ error Here the =⇒ means “evaluates to.” This symbol is not a part of the syntax of Scheme itself One can prevent the Scheme interpreter from evaluating a parenthesized expression by quoting it: (quote (+ 4)) =⇒ (+ 4) Here the result is a three-element list More commonly, quoting is specified with a special shorthand notation consisting of a leading single quote mark: ’(+ 4) EXAMPLE 10.4 Dynamic typing =⇒ (+ 4) Though every expression has a type in Scheme, that type is generally not determined until run time Most predefined functions check dynamically to make sure that their arguments are of appropriate types The expression (if (> a 0) (+ 3) (+ "foo")) will evaluate to if a is positive, but will produce a run-time type clash error if a is negative or zero More significantly, as noted in Section 3.5.3, functions that make sense for arguments of multiple types are implicitly polymorphic: 10.3 A Review/Overview of Scheme 511 (define (lambda (a b) (if (< a b) a b))) EXAMPLE 10.5 Type predicates The expression (min 123 456) will evaluate to 123 ; (min 3.14159 2.71828) will evaluate to 2.71828 User-defined functions can implement their own type checks using predefined type predicate functions: (boolean? x) (char? x) (string? x) (symbol? x) (number? x) (pair? x) (list? x) EXAMPLE 10.6 Liberal syntax for symbols ; ; ; ; ; ; ; is is is is is is is 10.7 a a a a a a a Boolean? character? string? symbol? number? (not necessarily proper) pair? (proper) list? (This is not an exhaustive list.) A symbol in Scheme is comparable to what other languages call an identifier The lexical rules for identifiers vary among Scheme implementations, but are in general much looser than they are in other languages In particular, identifiers are permitted to contain a wide variety of punctuation marks: (symbol? ’x$_%:&=*!) EXAMPLE x x x x x x x =⇒ #t The symbol #t represents the Boolean value true False is represented by #f Note the use here of quote ( ’ ); the symbol begins with x To create a function in Scheme one evaluates a lambda expression: Lambda expressions (lambda (x) (* x x)) =⇒ function The first “argument” to lambda is a list of formal parameters for the function (in this case the single parameter x ) The remaining “arguments” (again just one in this case) constitute the body of the function As we shall see in Section 10.4, Scheme differentiates between functions and so-called special forms ( lambda among them), which resemble functions but have special evaluation rules Strictly speaking, only functions have arguments, but we will also use the term informally to refer to the subexpressions that look like arguments in a special form A lambda expression does not give its function a name; this can be done using let or define (to be introduced in the next subsection) In this sense, a lambda A word of caution for readers familiar with Common Lisp: A lambda expression in Scheme evaluates to a function A lambda expression in Common Lisp is a function (or, more accurately, is automatically coerced to be a function, without evaluation) The distinction becomes important whenever lambda expressions are passed as parameters or returned from functions: they must be quoted in Common Lisp (with function or #’ ) to prevent evaluation Common Lisp also distinguishes between a symbol’s value and its meaning as a function; Scheme does not: if a symbol represents a function, then the function is the symbol’s value 896 Index Pascal (continued) if statement, 84, 102, 108, 248, 394; implementation, 8, 21, 736 limited extent of local objects, 209 mod operator, 374 nested subroutines, 124 new operation, 349 overloading, 146 packed types, 318, 321, 442 parameter passing, 115, 394ff pointers, 345ff, 349ff precedence levels, 223 records, 318ff repeat loop, 268 scope rules, 128, 385 semicolons, set types, 300, 316, 344, 374 short-circuit evaluation, lack of, 239, 249 standardization, statements and expressions, 229 strings, 104, 316, 343ff subrange types, 298 subroutine calling sequence, 390; 176ff subroutines as parameters, 401 type checking, 291, 303, 306 type compatibility, 311 type inference, 315 type system, 301, 380 variables as values, 226 variant records, 144; 165, 166, 139ff with statement, 15, 323; 30, 135ff Pascal’s triangle, 720ff; 328 pass of a compiler, 26, 731, 734 path of communication See communication path pattern matching See also regular expressions in awk, 664ff greedy, 701, 722 in Icon, 268, 288; 111ff minimal, 667, 701, 722 in ML, 129ff in scripting languages, 654, 696ff Patterson, David A., 74, 92, 109 PDA See automaton, push-down PDF (Portable Document Format), 156 and Postscript, 657 PE (Portable Executable) assemblies, 776, 780 peeking at characters in scanner, 53, 61 at tokens in parser, 68, 91, 93, 97 inside messages, 277 peephole optimization, 817; 321, 325ff Pentium processor, 810; 79, 81, 91, 102 See also x86 architecture perfect loop nest, 362 performance analysis, 24, 583, 809ff performance counters, hardware, 810 performance v safety, 178, 279; 348 performance versus safety, 236 Perl, 12, 650, 666ff, 718, 826 arrays, 328, 403, 706 blessing mechanism, 710 byte code, 790 canonical implementation, 654 and CGI scripting, 680 coercion, 704 context, use of, 653, 669, 704ff, 709ff; 51 economy of expression, 652 error checking, 704 first-class subroutines, 691 “force quit” example, 668ff hashes, 706 HTML header extraction example, 666ff I/O, 666; 157 inheritance, 712 last statement, 269 modules (packages), 133, 670, 707, 710 motto, 666 multiway assignment, 232 nested subroutines, 691, 721 numeric types, 705 objects, 673, 707, 710ff pattern matching, 131 and PHP, 826 regular expressions, 46, 667, 696, 698ff remote machine monitoring example, 681ff scope rules, 135, 140, 653, 691ff, 694ff selective aliasing, 707 strict ’vars’ mode, 691 syntax trees, 790 taint mode, 815 tied variables, 172 type checking, 131 typeglobs, 707 unlimited extent, 691 variables as values, 705, 710 Worse Is Better, 717 Perl just-in-time compilation, 790 object orientation, 673, 710 perlcc, 790 Perles, Micha A., 110 persistent files, 367; 154ff pervasive names, 134 Peterson, Gary L., 605, 647 Peyton Jones, Simon L., 543 PGAS (Partitioned Global Address Space) languages, 648 pH (language), 507, 516, 535, 633, 647, 824 phase of compilation, 25ff, 36, 730ff, 734; 323ff See also scanning; parsing; semantic analysis; code improvement; code generation φ function, in SSA form, 337ff PHP, 12, 650, 682ff, 826 arrays and hashes, 708 exception handling, 419 interactive form examples, 684ff modules (namespaces), 133 nested subroutines, lack of, 691 numeric types, 705 objects, 710ff, 712ff references, 446 regular expressions, 696 remote machine monitoring example, 683ff scope rules, 653, 691 self-posting, 684ff server-side web scripting, 682ff type checking, 653 Index variables as references or values, 705, 710 and XSLT, 292 phrase-level recovery from syntax errors, 99, 110; 2ff, 10ff PIC (position-independent code), 312ff Pierce, Benjamin C., 381; 251 pigeonhole principle, 19 piggy-backing of messages, 271 Pin binary rewriter, 796, 813, 816 pipeline stall, 79, 81, 91ff pipelining, 79, 91ff, 103 See also branch prediction; instruction scheduling branches and, 94ff caches and, 92ff pipes in scripting languages, 658ff PL/I, 826 decimal type, 296 exception handling, 419, 448 first-class labels, 426 formatted I/O, 157 history, indexed files, 156 label parameters, 244 pointers, 345 records, 324; 135 subroutines as parameters, lack of, 154 Plauger, Phillip J., 288, 759 pointer analysis, 334 pointer arithmetic, 178, 352 pointer reversal in garbage collection, 361ff pointer swizzling, 319 pointers, 345ff See also dangling reference; garbage collection; reference model of variables and addresses, 345 aliases and, 145 and arrays in C, 352ff, 396 as composite type, 300 frame pointer, 384 implementation, 345 in ML, 351 operations, 346ff and parameter passing in C, 396 semantic analysis and, 29 stack pointer, 384 to subroutines in C, 402 syntax, 346ff Polak, W., 448 Polish postfix notation, 206ff See also postfix notation polling for communication, 272 polymorphism, 114, 148ff, 290ff, 312, 317, 348, 381, 486ff, 505 ad hoc, 151 functional programming and, 508 object-oriented programming and, 486ff parametric, 149 explicit See generic subroutine or module implicit, 150, 291, 317, 505; 126 in Scheme, 510 subtype, 149, 292, 478 See also methods and method binding, dynamic type systems and, 291ff port, of a message-passing program, 263 portability, byte code, 8, 21ff, 766, 785, 797 character sets, 45 Diana, 304 Java, 279 nonconverting type casts, 310 numeric precision, 37, 294 Unix, virtual machines, 766 position-independent code (PIC), 312ff positional parameters, 405ff POSIX, 209 pthread standard, 431 regular expressions, 696ff select routine, 123 shell, 654, 656 Post, Emil, 506 post-test loop, 268 postcondition of subroutine, 178 postfix notation, 206ff, 221, 280 Postscript, 23, 206, 222, 657ff, 736, 738, 826; 156 Pouzin, Louis, 656 897 PowerPC architecture, 258, 585, 734, 792; 102ff, 109ff addressing modes, 75 AltiVec extensions, 645 atomic instructions, 608 condition codes, 77 condition-determining delay, 106 decimal arithmetic, 296 memory model, 612 powerset (in mathematics), 238 pragma (compiler directive), 65, 391, 421, 589, 804; 165 pre-test loop, 268 precedence, 280, 394 in CFG, 28, 50, 180 definition, 50 in lambda calculus, 239 of operators, 160, 220, 222ff, 235, 275; 228 precondition of subroutine, 178 predefined names, 44, 125, 134 keywords and, 61, 171 predefined type See type, predefined predicate in logic, 566; 253 in logic programming, 546 predicate calculus, 545, 566; 253ff Skolemization, 254, 257ff predication, 108 PREDICT sets, 79ff, 80 predict-predict conflict, 81 predictive parsing See parsing, top-down preemption, 580, 599ff prefetching, 180 prefix argument in Emacs Lisp, 678 prefix notation, 221, 280, 561 See also Cambridge Polish notation prefix property, of CFL, 20 preprocessor, 18, 20, 24 C++ compiler as, 21 pretty printer, 24 primary cache, 66 primitive type See type, primitive Princeton University, 507, 825 priority queue, 118 private base class, 463ff private member of class, 454ff 898 Index private type, in Ada, 414 procedural abstraction, 219 See also control abstraction procedure, 383 See also subroutine processes, 586, 598 lightweight and heavyweight, 586 threads and, 586, 598 processor See also architecture; microprocessor; multiprocessor; vector processor compiling for modern processors, 35; 91ff See also instruction scheduling; register allocation definition, 583 processor status register, 66, 76 processor/memory gap, 67 production, of CFG, 46 Proebsting, Todd A., 377 Proebsting’s Law, 377 prof, 810 profile-driven code improvement, 786ff profiler, 24, 797, 809ff basic block, 813, 816 program counter (PC), 66 program maintenance, programming environments, 24ff Genera, 39 for Smalltalk, 24ff Prolog, 7, 11, 505, 547ff, 574, 827 arithmetic, 551ff atoms, 547 backtracking, 552ff call predicate, 558, 564; 253 character set, 560 clause predicate, 565ff clauses, 547ff closed world assumption, 568ff control flow, 557ff cut (!), 557 database, 547 manipulation, 561ff execution order, 552ff, 557ff, 567 facts, 547, 565 fail predicate, 558 failure-directed search, 567 functors, 547 generator, 559ff goals, 548ff Horn clause, 547ff implementation, 23, 552ff, 567ff infinite regression, 554ff, 573 instantiation, 547, 553, 569 lists, 550ff loops, 559 negation, 568ff \+ (not) predicate, 556ff, 566, 568ff; 256 parallelization, 636 parentheses, 547 queries, 548, 552 recursive types, 365 reflection, 565, 799 resolution, 549ff rules, 547 search strategy alternatives, 567, 572 selection, 559 self-representation (homoiconography), 17, 561, 562 structures, 547 terms, 547 tic-tac-toe example, 554ff, 559, 562ff type checking, 547 unification, 547, 549ff, 552; 127 variables, 547, 549 prologue of subroutine, 117, 386 promise, 276 pronunciation, of language names, proof, constructive v nonconstructive, 507, 570 proof-carrying code, 815 proper list See list, proper property mechanism in C#, 455 proposition, in predicate calculus, 566; 253 protected base class, 463 protected member of class, 463 protected objects in Ada, 624; 273 prototype objects in JavaScript, 498, 710, 713ff pseudo-assembly notation, 214 pseudo-random number, 247, 526; 119 pseudoinstruction, 748; 88 pthread standard (POSIX), 431 ptrace, 808 public base class, 456 public member of class, 454 Pugh, William, 647 pumping lemma, 110 push-down automaton See automaton, push-down PVM (parallel virtual machine), 648 Python, 12, 650, 672ff, 827 arrays, 328, 707 canonical implementation, 654 equality testing, 369 exception handling, 419 executable class declarations, 715 as extension language, 652 first-class functions, 531, 655, 691 “force quit” example, 672ff hashes, 707 indentation and line breaks, 45, 673 interpretation, 18 iterators, 262, 264 lambda expressions, 508 list comprehensions, 367, 655 list types, 365 method binding, 480 modules, 135, 139, 670 multidimensional arrays, 708 multiple inheritance, 491 ambiguity resolution, 217 multiway assignment, 232, 708 nested subroutines, 124 numeric types, 670, 705 objects, 138, 450, 710ff, 714ff parameter passing, 405ff polymorphism, 149, 292 reflection, 565 regular expressions, 46, 674, 696 scope rules, 129, 653, 691ff sets, 708 try finally, 424 tuples, 409, 636, 708 type checking, 653, 704 unlimited extent, 691 variables as references, 472, 705, 710 visibility of class members, 465 Python Software Foundation, 672 Q quadruples, 735 qualified name, 125, 676, 800; 52, 135, quantifier, 566, 568ff; 253ff 42ff, Index quasiparallelism, 576 query in bash, 657ff in Prolog, 548, 552; 255ff query language processor, 23 quicksort, 379, 568, 572 Quine, Willard Van Orman, 221 Quiring, Sam B., 100, 110; quoting in shell languages, 660ff R R scripting language, 668, 827 arrays, 328, 668 automatic parallelization, 634 call by need, 525 first-class subroutines, 691 infix notation, 221 multidimensional arrays, 709 parameter passing, 402; 187 scope rules, 691ff super-assignment, 693 unlimited extent, 691 r-value, 226, 351; 52 Rabin, Michael O., 109 Alonzo Church and, 507 race condition, 578, 591, 601ff, 604, 613, 633 ragged array, 337 Rajwar, Ravi, 648 Ramesh, S., 284 Randell, Brian, 447 random number, pseudo, 247, 526; 119 random-access file, 156 range, of function, 534; 237 rational type See type, numeric, rational Rau, B Ramakrishna, 378 reaching definition, 336, 347, 367 read-eval-print loop, 509ff read-modify-write instruction See atomic instruction (primitive) read-only parameter, 398 read-write dependence See dependence, antireader–writer locks, 606, 625, 628, 641 ready list, 599ff, 604, 613ff, 640; 281 Real Time Specification for Java, 358 receive operation, 272ff explicit, 272ff, 278 implicit, 597; 272ff, 278, 280 peeking, 277 records, 317ff See also variant records; with statement assignment, 321 comparison, 321 as composite type, 300 fields, 318 ordering, 322 memory layout, 319ff, 597 holes, 320ff nested, 319 symbol table management, 29 syntax and operations, 318ff with statement, 99, 323; 367, 135ff recovery from syntax errors recursion, 43, 219, 270ff See also tail recursion algorithmically inferior programs, 274 continuation-passing style, 273 and functional programming, 505, 508 iteration and, 271ff mutual, 128 in Scheme, 515ff recursive descent, 70ff, 128 attribute management, 54 backtracking, 123 phrase-level recovery, 2ff v table-driven top-down parsing, 83 recursive types, 300, 345ff, 381 in Scheme, 513 redeclaration, 131 redirection of output, 658ff reduced instruction set computer See RISC reduction, 530, 533 redundancy elimination See also common subexpression elimination global, 336ff induction variables, 349 local, 328ff reentrant code, 613 reference counts, 358ff; 151, 166ff circular structures, 359 899 v tracing collection, 363 reference model of variables, 225ff, 233, 288ff, 345, 347ff, 371, 381, 396, 454, 472ff, 597 implementation, 227 references in C++, 446 forward, 189; 30 initialization and, 470, 472ff in PHP, 446 to subroutines, 152 and values, 220, 225ff referencing environment, 112, 122 binding and, 151ff referential transparency, 225, 534; 308 refinement of abstractions, 451 reflection, 143, 565, 745, 764, 799ff; 47 in C#, 802 and dynamic typing, 799, 804 and generics, 780, 802; 195, 196 in Java, 800ff pitfalls, 800 in Prolog, 565 regex library package, 696 register, 66 clock, 119 debugging, 809 FP See frame pointer memory hierarchy and, 66 PC (program counter), 66 processor status, 66, 76 saving/restoring, 386ff SP See stack pointer virtual, 730; 97, 323, 329ff in x86 and MIPS, 86ff register allocation, 391, 734, 741ff, 787, 788; 96ff, 366ff complexity, 322 graph coloring, 367, 377 and instruction scheduling, 99ff, 323, 370 in partial execution trace, 797 stack-based, 741 register indirect addressing mode, 75, 85 register interference graph, 367 register pressure, 323 common subexpression elimination and, 326, 344ff 900 Index register pressure (continued) induction variable elimination and, 349 instruction scheduling and, 354 loop reordering and, 362 software pipelining and, 358 register renaming, 82, 94ff, 352, 374 register spilling, 742; 97ff, 355, 369 register windows, 390ff; 181ff register-memory architecture (CISC machines), 75 register-register architecture (RISC machines), 75, 96 regular expressions, 3, 42ff, 696ff See also pattern matching advanced, 696 basic, 696 capture of substrings, 667, 699, 701ff, 722 compiling, 699, 702 creation from DFA, 14ff extended, 696ff greedy, 701, 722 grep, 46, 696ff Kleene star, 41, 44, 47 minimal matching, 667, 701, 722 nested constructs, lack of, 46 parentheses, 44 in Perl, 698ff POSIX, 696ff regex library package, 696 in scripting languages, 654, 696ff translation to DFA, 55ff translation to NFA, 699, 702 regular language (set), 43, 100 reification, 780, 802; 196 relocation, linking and, 744, 750ff, 770 remainder, in integer division, 374 rematerialization, 370 remote procedure call (RPC), 589; 278ff implementation, 763; 280ff implicit message receipt, 590; 272 message dispatcher, 280 parameters, 280 semantics, 279 remote-invocation send, 268 rendezvous, 278 repeat loop See loop, logically-controlled repeated inheritance See see inheritance, repeated replicated inheritance See see inheritance, repeated, replicated Reps, Thomas, 211 reserved word See keywords resolution, in logic programming, 546, 549ff resource hazard in pipeline, 91 return value of function, 116, 408ff, 508 reverse assignment, 485 reverse execution, 815 reverse Polish notation, 206ff See also postfix notation Rexx, 650, 652, 672, 724 context, use of, 653 error checking, 704 as extension language, 652 Object Rexx, 673 standardization, 654 Rice University, 648 Rice, H Gordon, 110 right-most (canonical) derivation, 48, 68, 87ff RISC (reduced instruction set computer), 213; 65, 81ff See also Alpha architecture; ARM architecture; MIPS architecture; PA-RISC architecture; PowerPC architecture; SPARC architecture byte operations, 69 compilation for, 91 conditional branches, 77 delayed branch, 93, 95 delayed load, 95 endian-ness, 69 history, xxiii, 88, 93ff, 103 implementation of, 81ff load-store (register-register) architecture, 75, 96 nullifying branches, 95 philosophy of, 81, 103 register windows, 390ff; 181ff registers, 66 subroutine calling sequence, 390 three-address instructions, 75 Ritchie, Dennis M., 8, 821 RMI See remote method invocation Robinson, John Alan, 549, 573 Rosenkrantz, Daniel J., 109, 210 Rosetta (Apple) binary translator, 791, 793, 795 Rosser, J Barclay, 537; 242 Church-Rosser theorem, 242 Rounds, William C., 210 Roussel, Philippe, 545, 574, 827 row-major layout (of arrays), 335ff; 360ff row-pointer layout (of arrays), 337ff RPC See remote procedure call RPG, 650 RTF (rich text format), 156 RTL (GNU register transfer language), 736, 759; 303, 309ff Rubin, Frank, 287 Ruby, 12, 650, 674ff, 682, 827 access control, 716 arrays, 328, 707 blocks, 676ff canonical implementation, 654 coercion, 704 continuations, 246 exception handling, 419, 655, 676 executable class declarations, 715 first-class subroutines, 691 “force quit” example, 675ff hashes, 707 iterators, 262, 267, 655, 676ff lambda expressions, 508 line breaks, 675 method binding, 480 mix-in inheritance, 491, 676 modules, 139, 670, 676 multilevel returns (catch and throw), 244, 245, 421 multiway assignment, 232, 655 nested blocks, 691, 721 nested subroutines, lack of, 691 numeric types, 670, 705 objects, 138, 450, 493, 655, 674, 710ff, 714ff polymorphism, 149, 292 Index on Rails, 651, 674 reflection, 655 regular expressions, 46, 676, 696 scope rules, 691 slices, 655 taint mode, 815 type checking, 653, 704ff unlimited extent, 691 variables as references, 472, 705, 710 rule, in Prolog, 547 run-time system, xxiv, 761ff See also coroutine; event handling; exception handling; garbage collection; library package; linkers and linking, dynamic; parameter passing, variable number of arguments; remote procedure call (RPC); thread; transactional memory definition, 761 relationship to compiler, 761, 812 Russell, Lawford J., 447 S S scripting language, 668 S-attributed attribute grammar See attribute grammar, S-attributed S-DSM See software distributed shared memory S-expression, 517; 309 SAC (Single Assignment C), 330, 507, 535 safety v performance, 178, 279; 348 safety versus performance, 236 Saltz, Joel, 376 sandboxing, 689, 796ff, 815, 816 Sandon, Lydia, 724 Sather, 448 satisfiability, 261 scalability in parallel systems, 594, 629 scalar type See type, scalar scaled index addressing mode, 85 scanner generator, 55ff, 60, 101 See also lex scanners and scanning, 3, 26, 27ff, 42, 51ff ad hoc, 52 with explicit finite automaton, 53, 60ff lexical errors, 63ff longest possible token rule, 53, 61ff nontrivial prefix problem, 61 table-driven, 63ff scatter operation, 272, 278, 280 scheduler-based synchronization, 588, 615ff scheduling, 599, 613ff; 281 See also context switch; instruction scheduling; multithreading; self-scheduling; trace scheduling implementation, 613ff on multiprocessor, 602 on uniprocessor, 599ff Scheme, 509ff, 827 See also Lisp apply function, 518ff assignment, 515ff association lists, 514 bindings, 512ff Boolean constants, 514 conditional expressions, 515, 538 continuations, 246, 284, 426 control flow, 515ff currying, 533 delay and force, 275, 635 denotational semantics, 210, 518 DFA example, 519ff equality testing, 369, 514ff eval function, 518ff evaluation order, 521ff expression types, 523 first-class functions, 156, 401, 691 iteration, 266 for-each, 516ff inexact constants, 103 lambda expression, 511, 531 lazy evaluation, 539 let construct, 129, 512; 137 lists, 513ff macros, 160, 523 map function, 530 nested subroutines, 124 numbers and numeric functions, 295, 514, 670, 705 operational semantics, 210 programs as lists, 517ff quoting, 510 rational type, 295 901 recursion, 515ff recursive declarations, 513 S-expressions, 517 scope rules, 122, 129ff, 140, 385, 513, 691 searching, 514 self-definition, 517ff self-representation (homoiconography), 122, 517ff, 562 special forms, 275, 285, 511, 523 symbols, 511 type checking, 653, 704 type predicate functions, 511 unlimited extent, 691 variables as references, 705 Scheme shell (scsh), 723 Scherer, William N III, iv Schiffman, Allan M., 499, 816 Schneider, Fred B., 647 Scholz, Sven-Bodo, 330, 536, 828 Schorr, Herbert, 361, 381 Schwartz, Jacob T., 380; 377 scientific notation and floating-point numbers, 72 scope, 3, 112, 121ff See also binding; binding rules; specific languages closed, 135; 31 dynamic, 122, 139ff, 291, 505 alternatives, 142 conceptual model, 695 motivation, 141 global variable, 123 hole in, 125, 129 implementation, 125, 143, 385; 29ff See also display; static link association list, 143; 33ff central reference table, 143; 33ff symbol table, 29ff lexical See scope, static local variable, 123 open, 135, 454 scripting languages, 653, 691ff static, 122ff classes, 136ff, 463ff declaration order, 127ff declarations and definitions, 130ff modules, 132ff, 460ff 902 Index scope (continued) nested blocks, 131ff, 512ff; 29 nested subroutines, 124ff; 29 own (static) variables, 124, 133 of undeclared variable in scripting language, 692ff scope resolution operator, 125, 455, 459; 218 scope stack of symbol table, 30ff scoped memory in Java, 358 Scott, Dana S., 109, 211 Alonzo Church and, 507 Scott, Michael L., iv, 642, 643, 647 scripting languages, 12, 649ff See also AppleScript; awk; bash; Emacs Lisp; JavaScript; Maple; Mathematica; Matlab; Perl; PHP; Python; R; Rexx; Ruby; S; Scheme; sed; SIOD; Tcl; Tk; VBScript; Visual Basic; XSLT access to system facilities, 654 arrays, 335 characteristics, 652ff, 691ff, 718 coercion, 148 data types, 654ff, 704ff composite, 706ff numeric, 705 declarations, 653 definition, 649 dynamic typing, 293, 653 extension languages, 652, 676ff first-class subroutines, 155 “force quit” example in Perl, 668ff in Python, 672ff in Ruby, 675ff in Tcl, 670ff garbage collection, 120, 346 general purpose, 668ff glue languages, 668ff history, 650ff interactive use, 652 magic numbers, 662 for mathematics, 667ff on Microsoft platforms, 651 modules, 133 names, 691ff object orientation, 710ff pattern matching, 654, 696ff polymorphism, 291 problem domains, 655 quoting, 660ff reflection, 565, 799, 803 report generation, 663ff scope rules, 653, 691ff shell languages, 655ff for statistics, 667ff string manipulation, 334, 342, 654, 696ff text processing, 663ff type checking, 291, 486 unlimited extent, 156 variable expansion and interpolation, 656ff, 701ff World Wide Web and, 680ff, 797 CGI scripts, 680ff client-side scripts, 686ff Java applets, 686ff server-side scripts, 680ff XSLT, XPath, and XSL-FO, 290ff scsh (Scheme shell), 723 search path of a shell, 658 Sebesta, Robert W., 39 second-class subroutine, 154ff secondary cache, 66 section of an array See arrays, slices security, 689 See also sandboxing and binary rewriting, 812 Common Language Infrastructure, 777, 781 v functionality, 689 Java Virtual Machine, 767, 776 JavaScript, 689 and reflection, 800 stack smashing, 353; 179 taint mode, 815 sed, 650, 663ff, 826 HTML header extraction example, 663 one-line scripts, 664 pattern space, 664 regular expressions, 46, 696 standardization, 654 seek operation, for files, 156 segmented memory, 345 segments, 745 segment switching in assembler, 749 select routine (POSIX), 123 Selection, 219 selection, 247ff case/switch statement, 251ff if statement, 247 in Prolog, 559 short-circuited conditions, 248ff, 278, 281 selection function See merge function, in SSA form Self (language), 498, 500, 710 self-definition See homoiconic language self-hosting compiler, 21 self-modifying code, 792 self-scheduling, 366 semantic action routine See action routine semantic analysis, 29ff, 175ff See also attribute grammar assertions, 178ff invariants, 178, 284, 288 pre- and postconditions, 178 symbol table and, 29 semantic check, 18, 175 See also semantic error dynamic, 141, 176ff, 365, 381; 34 arithmetic overflow, 238, 309 array subscript, 331, 340, 796; 350 conditional trap instruction, 89 dangling reference, 357, 796 disabling, 178 in linker, 756 reverse assignment, 484 safety v performance, 177 safety versus performance, 236 subrange values, 299, 315ff; 350 type conversion, 307ff, 311, 485 uninitialized variable, 234, 280, 796 variant records, 143, 145 static, 177 semantic error dynamic See also semantic check; type clash and lazy evaluation, 523 missing label in case statement, 254 null pointer dereference, 239, 366 unhandled exception, 420 static, 99 Index ambiguous method reference, 217, 222 attribute grammar handling, 199 declaration hiding local name, 131 invalid coercion in Ada, 311 invalid generic coercion in C++, 211 missing default constructor, 473 missing label in case statement, 254; 131 missing vtable in C++, 484 misuse of precedence in Pascal, 224 subrange and packed types as parameters in Pascal, 442 taking address of non-l-value, 310 type checking in ML, 126 unsupported operation on generic, 416 use before declaration, 128 semantic function, 181ff See also attribute grammar notation, 182ff semantic hook, 52 semantic stack, 57 semantics, 3, 42 See also attribute grammar axiomatic, 177, 178, 182, 211, 284, 545 denotational, 182, 210, 246, 293, 518 dynamic, 29, 140, 175 See also semantic check; semantic error of monitors, 621ff operational, 210 of remote procedure calls, 279 static, 29, 140, 175 v syntax, 41ff semaphores, 242, 617ff, 632 binary, 617 bounded buffer example, 618 send operation, 267ff buffering, 268ff emulation of alternatives, 271ff error reporting, 270ff synchronization semantics, 268ff, 271ff syntax, 271 sense-reversing barrier, 606 sentential form, 48 sentinel value, 280, 288 separate compilation, 113, 161ff, 750, 759; 39ff in C, 133 in C++, 455 and code improvement, 732 common blocks, 123 history, 44 and modules, 137, 461, 462 in scripting languages, 691 type checking, 751ff sequencing, 219, 246ff sequential consistency, 610ff sequential file, 155 serialization in concurrent program, 607 of objects in messages, 800 of transactions, 630 server-side web scripting, 680ff setjmp routine in C, 426ff SETL, 210, 380 sets, 344ff as composite type, 300 implementation, 344 in Python, 708 SGML (standard generalized markup language), 287ff sh, 650, 656 standardization, 654 shallow binding See binding rules, shallow shallow binding for name lookup in Lisp, 35 shallow comparisons and assignments (copies), 369ff Shamir, Eliahu, 110 shape of an array See array, shape shared inheritance See inheritance, repeated, shared shared memory (concurrent), 603ff See also synchronization v message passing, 583, 587ff scheduler implementation, 613ff Sharp, Oliver J., 378 Shasta, 288 Shavit, Nir, 647 shell, 650, 655ff, 668 See also bash; command interpreter; scripting languages Sheridan, Michael, 766 903 shift-reduce parsing See parsing, bottom-up shmem library package, 647 short-circuit evaluation, 188, 238ff, 248ff, 275, 278, 281, 538 side effect, 12, 230, 275ff, 560, 570ff and assignment operators, 230 and compilation, 536 and concurrency, 635 definition, 225 of exception handler, 423 and functional programming, 507ff, 534 and I/O, 525 of instruction, 368 and lazy evaluation, 276, 523ff; 187 and macros, 160 and nondeterminacy, 279; 119 and ordering, 236ff, 246ff, 525 in RTL, 309 in Scheme, 515ff and short-circuit evaluation, 240 of Smalltalk assignment, 228 of statement, 301 of subroutine call, 328 Siewiorek, Daniel P., 109 signal in monitor, 620ff cascading, 622 hints v absolutes, 621ff, 624 OS, 93, 435ff, 598, 601ff, 609 trampoline, 435 signaling NaN, floating-point, 234; 74 significand of floating-point number, 72 significant comment See pragma Silbershatz, A., 284 Silicon Graphics, Inc., 585; 85 simple type See type, simple Simula, 136, 173, 448, 828 cactus stacks, 432 call-by-name parameters, 402; 185ff classes, 138 coroutines, 428 detach operation, 429, 433 encapsulation, 450, 460 inheritance, 491 method binding, 480 904 Index Simula (continued) object initialization, 475 parameter passing, 185ff type system, 294 variables as references, 472 virtual methods, 480 simulation, 433, 792; 205ff Singh, Jaswinder Pal, 648 Single Assignment C, 328, 330, 507, 535, 633, 828 single inheritance, 483ff single stepping, 808ff single-assignment variable, 636ff single-precision floating-point number, 68, 73 SIOD (Scheme in One Defun), 677, 724 and GIMP, 677 Sipser, Michael, 109 Sisal, 11, 507, 516, 535ff, 633, 828 compilation, 536 Skolem, Thoralf, 254 Skolemization, 254, 257ff slice of an array, 328ff, 668; 366 SLL parsing See parsers and parsing, top-down SLR parsing See parsers and parsing, bottom-up Smalltalk, 7, 12, 173, 450, 493ff, 619, 828; 227ff anthropomorphism, 471, 493 assignment, 228 associativity and precedence, lack of, 228 blocks, 228 class hierarchy, 471 classes, 138 control abstraction, 229ff expression syntax, 394, 438; 227 if construct, 394; 228 implementation, 23, 499 infix notation, 221 inheritance, 491 interpretation, 18 iteration, 267; 228ff messages, 227 metaclass, 472 method binding, 480 multiple inheritance, 499 object initialization, 470ff Object superclass, 457 object-oriented programming and, 493; 227ff parameter passing, 396 polymorphism, 114, 149, 291ff precedence, 224 programming environment, 24ff, 39, 493; 153, 154, 227 self, 451; 230 super, 459 type checking, 114, 179, 291, 485 type system, 293ff unlimited extent, 156 variables as references, 226, 472 visibility of class members, 465 Smith, James E., 109 Smith, Randall B., 500 Sneeringer, W J., 380 Snobol, 828; 123 pattern matching, 131 scope rules, 122, 140 self-representation (homoiconography), 562 strings, 334, 342 type checking, 131 snooping (cache coherence), 584 Snyder, Alan, 448 SOAP, 648 Soci´et´e des Outils du Logiciel, 823 socket, 263 software distributed shared memory (S-DSM), iii, 288, 587, 648 software pipelining, 356ff Solomon, Marvin H., 288 sourceforge.net, SPARC architecture, 585, 759; 102ff, 109 addressing modes, 75 atomic instructions, 606 condition codes, 77 fence instructions, 611 memory model, 612 register windows, 391; 181ff Rock implementation, 631 special forms in Scheme, 275, 285, 511, 523, 645 speculation, 219 code caching, 786 code improvement, 180 OR parallelism, 636 processor execution, 82, 92, 108 transactions, 630ff spilling of registers See register spilling spin lock, 604ff, 614ff and preemption, 643 two-level, 640 spin-then-yield lock, 614ff spinning See synchronization, busy-wait spreadsheet, 11 SQL, 11, 23, 573, 577, 806 SR, 828 bounded buffer example, 276, 278 capabilities, 265 case statement, lack of, 116 function return value, 409 guarded commands, 115, 122 implementation, 757 in statement, 118, 276 integration of sequential and concurrent constructs, 597 line breaks, 45 memory model, 265 message screening, 119, 276 naming for communication, 265 nondeterminacy, 115 receive operation, 272 remote invocation, 268 send operation, 268 termination, 284 threads, 428, 590 Srivastava, Amitabh, 816 SSA form See static single assignment form stack frame, 117ff, 384ff; 173ff bookkeeping information, 117 with dynamic shape arrays, 334 return value, 409 temporaries, 116 with variable number of arguments, 407 stack pointer, 118, 384 stack smashing, 353; 179 stack-based allocation and layout, 117ff, 384ff, 745 See also calling sequence; stack frame Index backtrace, 810, 815 for coroutines, 430ff exceptions, 425ff for iterators, 202 for nested thread See cactus stack stack-based intermediate language, 736, 766 See also Forth; byte code; Postscript optimization, 766 stall of processor pipeline See pipeline stall standard input and output, 659 standardization, Stanford University, 10, 447; 85, 109 Stansifer, Ryan D., 543, 825 start symbol of CFG, 46 statement v expression, 220, 225, 229 in predicate calculus, 566; 253 static analysis, 179ff See also alias analysis; escape analysis; semantic check, static; subtype analysis static binding See binding, static static chain, 127ff, 385 v display, 389 maintaining, 387 static link, subroutine, 126, 385 static linker, 750 static method binding, 479 static objects, storage allocation, 115ff, 124, 133 static scoping See scope, static static semantics See semantics, static static single assignment (SSA) form, 788; 307, 336ff, 378 static typing See type checking, static stdio library, in C/C++, 406; 159, 161 Stearns, Richard E., 109, 210 Steele, Guy L Jr., 822, 827 stop-and-copy garbage collection, 362ff, 381 stop-the-world phenomenon in garbage collection, 363 storage allocation and management, 114ff See also dangling reference; garbage collection; memory, leak storage compaction, 120; 151 store_conditional instruction, 608, 630, 641 stored program computing, 11 Stoy, Joseph E., 210, 211 Strachey, Christopher, 211 streams in C++, 162ff in functional programming, 525ff, 540 and Unix tools, 697 strength reduction, 326, 349 strict language, 523 strict name equivalence, 306 strictness analysis, 536 strings, 300, 342ff and scripting languages, 654, 663, 696ff storage management, 343 strip mining, 366 Strom, Robert E., 380 strongly typed language See type checking, strong Stroustrup, Bjarne, 499, 822; 215, 218 structural equivalence of types, 303ff, 377, 753; 132 structured programming, 7, 241ff, 287; 347 goto alternatives, 242ff, 278 structures, 317ff See also records in Prolog, 547 stub for dynamic linkage, 314 in RPC, 806; 278 Stumm, Michael, 640 stylesheet languages, 288 subclass See class, derived subrange type, 298ff, 315ff subroutine, 219, 383ff See also calling sequence; control abstraction; function; leaf routine; parameter passing; parameters; stack frame; stack-based allocation and layout closure See closure, subroutine epilogue, 117, 386 905 first-class See first-class values, subroutines; function, higher-order formal, 401 See also first-class values, subroutines frame pointer, 117, 118, 384 generic See generic subroutine or module impact on code generation and improvement, 454, 100ff in-line See in-line subroutine nested See nesting, of subroutines object-oriented programming, 455ff pointer to, in C, 402 prologue, 117, 386 reference to, 152 second-class, 154ff stack pointer, 118, 384 static allocation for, 116 subtype, 306, 311, 478 See also class, derived constrained, 299, 315 subtype analysis, 179, 483 subtype polymorphism See polymorphism, subtype success, of computation in Icon, 294; 112 Sun Microsystems, Inc., 585, 670, 688, 766, 824 HotSpot JVM, 380, 767, 788ff multiprocessors, 83 Sundell, H˚akan, 646 SUNY Stony Brook, 824 super-assignment in R, 693 superclass See class, base superscalar processor, 35, 577; 82, 378 Suraski, Zeev, 826 Sussman, Gerald Jay, 173, 543, 827 Sweeney, Peter F., 499 Swing, 436ff, 687; 154 switch statement See case/switch statement symbol table, 29, 32, 143, 739; 29ff and action routines, 196 and attribute grammar, 739 and dynamic linking, 763 and interpretation, 808 in Java class file, 768, 771 906 Index symbol table (continued) mutual recursion with syntax tree, 348 in object file, 33, 744, 791, 799ff passing with inherited attributes, 184 scope stack, 30ff semantic analyzer and, 29, 730 with statements, 30ff, 135 symbol, external, 744 Symbolics Corp., 39 Syme, Don, 447, 823 symmetric multiprocessor, 583 synchronization, 436, 578, 587ff See also barrier; mutual exclusion; transactional memory in Ada 95, 624ff blocking See synchronization, scheduler-based busy-wait (spinning), 587, 604ff, 615 barriers, 606ff and preemption, 643 spin locks, 604ff, 614ff, 640 condition synchronization, 603, 616ff definition, 587 of event handler, 436, 609; 153 granularity, 629 implicit, 633ff instruction, 611ff in Java, 626ff in message passing, 268ff nonblocking, 607ff, 646 scheduler-based, 588, 599ff, 615ff See also blocking (of process/thread); conditional critical region; monitor; semaphore synchronization send, 268 synchronized method of a Java class, 626 syntactic sugar, 221; 130, 162 array access in Ruby, 707 array subscripts, 328, 352 CALL channels in Occam, 264 definition, 147 equality in Prolog, 549 extension methods in C# 3.0, 468 method calls in Ruby, 675 monads, 526 object orientation in Perl, 711 origin of term, 173 properties in JavaScript, 708 regular expressions in Ruby, 676 synchronized methods, 626 tail recursion, 516, 535, 633 test in bash, 658 syntax, 3, 28, 41ff See also context-free grammar; regular expressions recursive structure and, 43 v semantics, 41ff syntax analysis See parsers and parsing; scanners and scanning syntax error, 72, 99ff; 1ff bottom-up recovery, 10ff context-specific look-ahead, 99; 3ff, error productions, 99 misspelling, 27 panic mode recovery, 99; 1ff, 10ff phrase-level recovery, 99, 110; 2ff repair, syntax tree, abstract, 32, 33, 67, 191 attribute grammars and, 189ff, 197 averaging example, 757 basic blocks of, 96, 328 in C#, 789 combinations example, 328ff construction of, 176ff, 189ff, 194 decoration (annotation) of, 32, 176ff, 197ff, 249 in Diana, 304ff GCD example, 32ff, 730ff in integrated development environment, 25 and local code improvement, 334 mutual recursion with symbol table, 348 v parse tree, 73 in Perl, 790 semantic analysis and, 176ff semantic errors and, 199ff syntax tree, concrete See parse tree syntax-directed translation, 67 synthesized attribute See attribute, synthesized T table-driven parsing See also parsers and parsing bottom-up, 92ff top-down, 76ff table-driven scanning, 63ff tag of a variant record, 234; 139 tail recursion, 272ff, 516, 535, 597; 348 taint mode in Perl and Ruby, 815; 377 Tanenbaum, Andrew S., 381 target code generation compilation phase, 26, 33ff task, 586 task parallelism, 594 Tcl (tool command language), 12, 650, 652, 670ff, 828 See also Tk in AOLserver, 677 arrays and hashes, 708 canonical implementation, 654 comments, 672 context, use of, 653 error checking, 704 as extension language, 652, 672 “force quit” example, 670ff Incr Tcl, 673 line breaks, 45, 672, 673 modules, 670 nested subroutines, 691 numeric types, 705 regular expressions, 671, 696 scope rules, 653, 691ff self-representation (homoiconography), 562 strings as internal data format, 691 variables as values, 705 TCOL, 303 TCP Internet protocol, 637; 265, 270 Teitelbaum, Timothy, 211 template metaprogramming, 160; 190 templates, in C++, 149ff, 411, 415ff, 457, 487; 127, 189ff See also generic subroutine or module temporal loop, in relaxed memory model, 611ff temporary file, 367; 154 Tera architecture, 636 term, in Prolog, 547 Index terminal, of CFG, 46 termination in distributed systems, 274ff, 277, 284 test_and_set instruction, 605ff, 616 TEX, 10, 23, 723, 738 dynamic scoping, 140 text files See files, text text processing, in scripting languages, 663ff theorem proving, automated, 256 this parameter, 462ff Thomas, David, 827 Thompson, Kenneth, 8, 295, 656, 697 Thompson shell, 656 thread, 586 See also concurrency; context switch; multithreading; scheduling coroutines and, 429 creation, 589ff co-begin , 589ff, 593 early reply, 597 implicit receipt, 597; 272 See also remote procedure call in Java 2, 594 in Java 5, 596ff launch-at-elaboration, 592ff parallel loops, 590ff for event handling, 436 implementation, 598ff, 763 preemption, 601ff v process, 586, 598 stack frame See also cactus stack threading of state in functional programs, 527 thunk, 447; 185ff, 279 tic-tac-toe example in Prolog, 554ff, 559, 562ff Tichy, Walter F., 759 tiling, 360 timeout in message passing, 274 timing window, 602 See also race condition Titanium, 648 Tk, 652, 670, 828 tokens, 18, 27, 43ff See also scanners and scanning examples, 27 misspellings, 27 prefixes, 61ff regular expressions and, 43ff tombstones (for dangling reference detection), 381; 149ff, 166 reference counts, 360; 151 Top 500 list, 645 top-down parsing See parsing, top-down topological sort, 571; 353 Torczon, Linda, 39, 211, 759; 109, 377 trace scheduling, 180 tracing garbage collection, 360ff v reference counts, 363 trailing part of LR production, 195; 53 trampoline in closure implementation, 179 for signal handling, 435 transactional memory, xxii, 543, 629ff; 103 bounded buffer example, 630 challenges, 633 implementation, 631, 763 nonblocking, 646 retry , 630, 632 transfer operation for coroutine, 432ff transition function of finite automaton, 13 of LR-family parser, 91 of push-down automaton, 18 of table-driven scanner, 63 translation scheme, 187 See also attribute flow; attribute grammar ad hoc, 191 See also action routine Transmeta Corp., 792 transparency, 279 transputer, INMOS, 826 trap instruction, 808; 89 TreadMarks, 648 tree grammar, 197ff, 735 v context-free grammar, 198 trie, 61 trivial update problem, 535, 536 troff, 23, 738 true dependence See dependence, flow tuple, 232; 127, 129 tuple space in Linda, 636, 824 Turing (language), 828 aliases, 145 907 and Euclid, 138 modules, 133, 138 scope rules, 135 side effects, 238, 247 Turing Award, 506 See also entries for Fran Allen; John Backus; O.-J Dahl; Edsger Dijkstra; Tony Hoare; Kenneth Iverson; Alan Kay; Donald Knuth; Butler Lampson; John McCarthy; Robin Milner; Kristen Nygaard; Michael Rabin; Dennis Ritchie; Dana Scott; Ken Thompson; Alan Turing; Niklaus Wirth Turing, Alan, 506ff Alonzo Church and, 507 Turing completeness, 7, 523, 573; 190 Turing machine, 506 Turner, David A., 825 two’s complement arithmetic, 238, 307; 69, 70ff two-level locking, 640 type, 217 alias, 305 anonymous, 307 Boolean, 294 See also short-circuit evaluation built-in, 293ff cardinal, 295 classification, 294ff complex, 295 composite, 293, 300ff See also arrays; files; lists; pointers; records; variant records; sets inference and, 315ff in scripting languages, 654ff, 706ff constructed, 300 derived, 306 discrete, 251, 296 enumeration, 297ff logical, 294 numeric, 294ff See also floating-point arbitrary precision (bignums), 705 decimal, 296; 89 fixed-point, 296 multi-length, 299 rational, 295, 705 908 Index type (continued) in Scheme, 514 in scripting languages, 705 unsigned, 295 opaque, 135, 461ff ordinal See type, discrete packed, 318, 321, 442 predefined, 293 primitive, 293 recursive, 128, 300, 345ff, 381 scalar, 297 simple, 297 subrange, 298ff, 315ff universal reference, 313ff unnamed, 307 type attribute, in Ada, 378, 404, 414 type cast, 307ff dynamic, 309, 484ff nonconverting, 303, 309ff static See type conversion type checking, 291, 303ff See also coercion; type equivalence; type compatibility; type inference with attribute grammar, 197ff dynamic, 140, 291ff scripting languages and, 653 v static, 292 linking and, 751ff in ML, 316ff; 126ff with separate compilation, 751ff static, 291 strong, 291 and garbage collection, 359 type predicate functions in Scheme, 511 and universal reference type, 313ff type clash, 141, 200ff, 291, 297 and equality testing in Java and C#, 230 and inheritance, 486 in Scheme, 510 in Smalltalk, 486 type class, in Haskell, 446; 129 type compatibility, 289ff, 303, 310ff, 709ff type conformance, 380 type consistency in ML, 126 type constraint, 299 for generics, 414ff; 196 type constructor, 113, 300, 302; 130 type conversion, 303, 307ff, 484 type descriptor for dynamic typing and method dispatch, 486 for garbage collection, 359, 361 for reverse assignment, 484 type equivalence, 289ff, 303ff name, 303ff, 753 structural, 303ff, 377, 753; 132 type erasure, 194ff type extension, 449, 466ff, 494, 825 See also class type hierarchy analysis, 499 type inference, 290, 303, 314ff, 574, 709ff, 825 for composite types, 315ff and generics, 488 in ML, 316 for static method dispatch, 499 for subranges, 315ff type predicate functions in Scheme, 511 type propagation, 499 type pun See type cast, nonconverting type system, 290ff See also polymorphism; type checking definition and point of view, 293ff orthogonality, 301ff polymorphism and, 291ff purpose, 289 type variable, 126 typeglobs in Perl, 707 types self-descriptive, 313 typestate, 380 U UCS (Universal Character Set), 295 See also Unicode UDP Internet protocol, 265, 270 Ullman, Jeffrey D., 109 undeclared variables, scope of in scripting languages, 692ff Ungar, David, 500 Unicode, 45, 294ff, 343 character entities, 295; 292 collating elements, 698 unification, 570 in C++ templates, 127 cost, 381 in logic programming, 546ff, 549ff, 552, 558, 636; 127 in ML, 292, 316, 381; 127 Unified Parallel C (UPC), 648 uniform object model, 492 uninitialized variable, 233, 234, 745, 796 unions See variant records unit number (in Fortran I/O), 157 universal quantifier, 253ff universal reference type, 313ff, 442 universe type, of set, 344 University of Aix–Marseille, 545, 574, 827 University of Arizona, 824, 828 University of California at Berkeley, 109 University of California at Los Angeles, 507 University of Edinburgh, 545, 574, 827 University of Hertfordshire, 828 University of Rochester, v University of Toronto, 828 University of Wisconsin–Madison, v, 648 Unix, 20 See also Linux and C, 821 grep, regular expressions and, 46, 697 IRIX, 312 magic numbers, 662, 774 prof and gprof, 810 ptrace, 808 SunOS, 759 text files, 156 unlimited extent See extent, of object unnamed type See type, unnamed unsigned integer language-level, 295 machine-level, 69, 70 unstructured control flow, 220, 241ff unwinding of subroutine call stack on exception, 245; on non-local goto, 243, 245; 186 UPC (Unified Parallel C), 648 urgent queue of monitor, 621 URI (uniform resource identifier) of Applet, 687 of CGI script, 680ff Index of document type definition (DTD), 289 manipulation in XSLT, 295 in Perl, 683 v URL, 680 useless instruction, 326, 345 useless symbol in CFG, 49 Usenet, 287 UTF-8 character encoding, 295 V Val (language), 11, 516 Valgrind, 171 value model of variables, 225ff, 345, 371, 395, 396, 454, 472ff value numbering, 377 global, 336ff local, 331ff values initialization and, 470, 472ff l-value, 226, 300, 310, 313, 351; 52 r-value, 226, 351; 52 and references, 220, 225ff van Rossum, Guido, 672, 827 van Wijngaarden, A., 821 variables See also initialization; names; reference model of variables; scope; value model of variables in CFG, 46 interpolation (expansion) in scripting languages, 656ff, 701ff in logic programming, 546, 547, 549 semantic analysis and, 29 undeclared, scope of in scripting languages, 692ff variance, of vector, 97ff variant records (unions), 234, 310, 317, 324ff; 139ff as composite type, 300 constrained, 144 and garbage collection, 359 v inheritance, 325 memory layout, 145 v nonconverting casts, 324 safety, 141ff tag checks, 179; 143, 145 VAX architecture, 793 arguments pointer, 440 endian-ness, 374; 69 length of instructions, 81 pipelining, 81 subroutine call, 440; 213 three-address instructions, 75 VBScript, 650ff vector processor, 577, 591, 633; 373, 378, 365ff very busy expression VES (Virtual Execution System) See Common Language Infrastructure VEST binary translator, 793, 816 viable prefix, of CFG, 19 view of an object, 215 virtual machine, xxiii, xxiv, 19, 764ff, 816 See also Common Language Infrastructure; Java Virtual Machine v interpretation, 17, 18, 764 language-specific, 764 process v system, 765 Smalltalk, 816 virtual machine monitor (VMM), 765 virtual method table, 483ff virtual methods See methods and method binding, virtual virtual registers, 730; 97, 323, 329ff See also register allocation and available expressions, 341ff and live variable analysis, 345 and value numbering, 331, 336ff visibility of members in object-oriented languages, 456, 463 VisiCalc, 573 visitor pattern, 287, 490 Visual Basic, 776, 821 See also Basic; VBScript and scripting, 677ff, 686, 718, 797 Visual Basic for Applications (VBA), 651 Visual Studio, 25 VLSI, 213; 80 VMWare, 765 volatile variable, 427, 613, 628 von Neumann, John, 11 von Neumann language, 11 vtable (virtual method table), 483ff 909 W Wadler, Philip, 536, 544 Wahbe, Robert, 816 Waite, William H., 361, 381 Wall, Larry, 650, 666, 826 Wand, Mitchell, 288, 448 watchpoints, 807ff Watt, David A., 210 web browser, 579ff scripting, 651, 677, 680, 686ff web crawler, 723 Wegman, Mark N., 377 Wegner, Peter, 173, 381, 500; 251 Weinberger, Peter, 664 Weiser, Mark, 381 Weiss, Shlomo, 109 Welsh, Jim, 380 Wettstein, H., 643 while loop See loop, logically-controlled white space, 45 wildcards, in shell languages, 656 Wilhelm, Reinhard, 543; 233 Wilson, Paul R., 381 Wiltamuth, Scott, 821 Winch, David, 724 Windows Forms, 436 Windows operating system, 22 See also NET on Alpha architecture, 793 object file format, 781 scripting, 651 text files, 156 Win32 threads package, 588 Windows Presentation Foundation (WPF), 436 Windows Script, 651 Wirth, Niklaus, 8, 21, 39, 85, 100, 110, 137, 173, 242, 287, 297, 821, 825, 826; 2, 158 Wisniewski, Robert, 643 with statement, 323; 135ff, 367 Wolfe, Michael, 378 workspace (e.g., in Smalltalk or Common Lisp), 154 World Wide Web See also scripting languages, World Wide Web and 910 Index character model standard, 381 and the growth of parallel computing, 589 and the growth of scripting, 503, 650, 717 security, 689 World Wide Web Consortium, 680, 686, 688, 724, 829; 289 Worse Is Better, 717, 724 WPF (Windows Presentation Foundation), 436 write buffer, 610 write-read dependence See dependence, flow write-write dependence See dependence, output Wulf, William A., 759 WYSIWYG (what you see is what you get), 619 X X10, 648 x64 architecture See x86-64 architecture x86 architecture, 22, 585, 793, 794, 796; 65, 84ff assembly language, 5, 33 atomic instructions, 606, 611 binary coded decimal, 89 compilation for, 91 condition-determining delay, 106 conditional branches, 77, 89 debugging registers, 809 endian-ness, 69 floating-point, 85, 86, 89 machine language, memory model, 612 MMX extensions, 645; 86 nop s, 748 Pascal calling sequence, 390; 176ff prefix code for instruction, 89 register set, 739; 86ff segmentation, 745 SSE extensions, 645; 87ff two-address instructions, 75 x86-64 architecture, 585, 796; 84, 86, 103, 107 XCode, 25 Xerox Palo Alto Research Center (PARC), 39, 493, 619, 823, 828; 153, 227 XHTML, 690, 724, 829; 288ff quote presentation example, 289ff XML (extensible markup language), 689ff, 829; 287ff case sensitivity, 288 declarations, 289 namespaces, 289, 294 tree structure, 289 well-formedness, 288 XML Schema, 289 XPath, 829; 290ff, 294ff XSD (XML Schema Definition language), 289 XSL (extensible stylesheet language), 690, 829; 287ff XSL-FO (XSL formatting objects), 829; 290ff XSLT (XSL transforms), 11, 573, 690ff, 829; 287ff bibliographic formatting example, 292ff Y yacc, 42, 92, 101, 109 action routines, 49ff error recovery, 10ff Yale University, 824 Yang, Junfeng, 377 Yeatman, Corey, 110 Yellin, Frank, 759 yield, of derivation, 48 Yochelson, Jerome C., 381 Younger, Daniel H., 67 Z Zadeck, F Kenneth, Zhao, Qin, 816 377 ... Scheme does), we have 522 Chapter 10 Functional Languages (double (* 4)) =⇒ (double 12) =⇒ (+ 12 12) =⇒ 24 Under normal-order evaluation we would have =⇒ =⇒ =⇒ =⇒ EXAMPLE 10 .23 Normal-order avoidance... b) a b))) EXAMPLE 10.5 Type predicates The expression (min 123 456) will evaluate to 123 ; (min 3.14159 2. 71 828 ) will evaluate to 2. 71 828 User-defined functions can implement their own type checks... Order Revisited Start 521 q0 q1 0 0 q2 q3 (define zero-one-even-dfa ’(q0 (((q0 0) q2) ((q0 1) q1) ((q1 0) q3) ((q1 1) q0) ((q2 0) q0) ((q2 1) q3) ((q3 0) q1) ((q3 1) q2)) (q0))) ; start state

Ngày đăng: 16/05/2017, 09:12

Từ khóa liên quan

Mục lục

  • Front Cover

  • Programming Language Pragmatics

  • Copyright

  • Table of Contents

  • Foreword

  • Preface

  • Part I: Foundations

    • Chapter 1. Introduction

      • 1.1 The Art of Language Design

      • 1.2 The Programming Language Spectrum

      • 1.3 Why Study Programming Languages?

      • 1.4 Compilation and Interpretation

      • 1.5 Programming Environments

      • 1.6 An Overview of Compilation

        • 1.6.1 Lexical and Syntax Analysis

        • 1.6.2 Semantic Analysis and Intermediate Code Generation

        • 1.6.3 Target Code Generation

        • 1.6.4 Code Improvement

        • 1.7 Summary and Concluding Remarks

        • 1.8 Exercises

        • 1.9 Explorations

        • 1.10 Bibliographic Notes

        • Chapter 2. Programming Language Syntax

          • 2.1 Specifying Syntax: Regular Expressions and Context-Free Grammars

            • 2.1.1 Tokens and Regular Expressions

Tài liệu cùng người dùng

Tài liệu liên quan