ebook img

Essentials of Programming Languages, 3rd Edition PDF

433 Pages·2008·3.41 MB·english
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Essentials of Programming Languages, 3rd Edition

computer science/programming languages PE RS Essentials of Programming Languages OS E third edition G N ESSENTIALS OF Daniel P. Friedman and Mitchell Wand R T A This book provides students with a deep, working understanding of the essential concepts of program- I MA ming languages. Most of these essentials relate to the semantics, or meaning, of program elements, L PROGRAMMING and the text uses interpreters (short programs that directly analyze an abstract representation of the M S THIRD EDITION program text) to express the semantics of many essential language elements in a way that is both clear IO and executable. The approach is both analytical and hands-on. The book provides views of program- N ming languages using widely varying levels of abstraction, maintaining a clear connection between the F G LANGUAGES high-level and low-level views. Exercises are a vital part of the text and are scattered throughout; the text explains the key concepts, and the exercises explore alternative designs and other issues. The complete L Scheme code for all the interpreters and analyzers in the book can be found online through The MIT A Press website. N For this new edition, each chapter has been revised and many new exercises have been added. G Significant additions have been made to the text, including completely new chapters on modules and U continuation-passing style. Essentials of Programming Languages can be used for both graduate and un- dergraduate courses, and for continuing education courses for programmers. A G Daniel P. Friedman is Professor of Computer Science at Indiana University and is the author of many E books published by The MIT Press, including The Little Schemer (fourth edition, 1995), The Seasoned S Schemer (1995), A Little Java, A Few Patterns (1997), each of these coauthored with Matthias Felleisen, and The Reasoned Schemer (2005), coauthored with William E. Byrd and Oleg Kiselyov. Mitchell Wand is Professor of Computer Science at Northeastern University. T H M I R D “With lucid prose and elegant code, this book provides the most concrete introduction to the few build- D D ing blocks that give rise to a wide variety of programming languages. I recommend it to my students and A E L look forward to using it in my courses.” D I I M —Chung-chieh Shan, Department of Computer Science, Rutgers University TI 9 O 5 5 N 4 “Having taught from EOPL for several years, I appreciate the way it produces students who understand 7 2 the terminology and concepts of programming languages in a deep way, not just from reading about the 3 concepts, but from programming them and experimenting with them. This new edition has an increased /2 F 2 emphasis on types as contracts for defining procedure interfaces, which is quite important for many r /0 i 8 students.” e C d Y —Gary T. Leavens, School of Electrical Engineering and Computer Science, University of Central Florida m A N a M “I’ve found the interpreters-based approach for teaching programming languages to be both compelling n A and rewarding for my students. Exposing students to the revelation that an interpreter for a program- a G n Y ming language is itself just another program opens up a world of possibilities for problem solving. The d E L third edition of Essentials of Programming Languages makes this approach of writing interpreters more W O accessible than ever.” B a L —Marc L. Smith, Department of Computer Science, Vassar College n A d C K 978-0-262-06279-4 Daniel P. Friedman and Mitchell Wand The MIT Press Massachusetts Institute of Technology Cambridge, Massachusetts 02142 http://mitpress.mit.edu Essentials of Programming Languages third edition Essentials of Programming Languages third edition Daniel P. Friedman Mitchell Wand TheMITPress Cambridge,Massachusetts London,England ©2008DanielP.FriedmanandMitchellWand All rights reserved. No part of this book may be reproduced in any form by any electronicormechanicalmeans(includingphotocopying,recording,orinformation storageandretrieval)withoutpermissioninwritingfromthepublisher. MITPressbooksmaybepurchasedatspecialquantitydiscountsforbusinessorsales promotional use. For information, please email [email protected] write to Special Sales Department, The MIT Press, 55 Hayward Street, Cambridge, MA02142. ThisbookwassetinLATEX2εbytheauthors,andwasprintedandboundintheUnited StatesofAmerica. LibraryofCongressCataloging-in-PublicationData Friedman,DanielP. Essentialsofprogramminglanguages/DanielP.Friedman,Mitchell Wand. —3rded. p. cm. Includesbibliographicalreferencesandindex. ISBN978-0-262-06279-4 (hbk.:alk.paper) 1.ProgrammingLanguages(Electroniccomputers).I.Wand, Mitchell.II.Title. QA76.7.F73 2008 005.1—dc22 2007039723 10987654321 Contents ForewordbyHalAbelson ix Preface xv Acknowledgments xxi 1 InductiveSetsofData 1 1.1RecursivelySpecifiedData 1 1.2DerivingRecursivePrograms 12 1.3AuxiliaryProceduresandContextArguments 22 1.4Exercises 25 2 DataAbstraction 31 2.1SpecifyingDataviaInterfaces 31 2.2RepresentationStrategiesforDataTypes 35 2.3InterfacesforRecursiveDataTypes 42 2.4AToolforDefiningRecursiveDataTypes 45 2.5AbstractSyntaxandItsRepresentation 51 3 Expressions 57 3.1SpecificationandImplementationStrategy 57 3.2LET:ASimpleLanguage 60 3.3PROC:ALanguagewithProcedures 74 3.4LETREC:ALanguagewithRecursiveProcedures 82 3.5ScopingandBindingofVariables 87 3.6EliminatingVariableNames 91 3.7ImplementingLexicalAddressing 93 vi Contents 4 State 103 4.1ComputationalEffects 103 4.2EXPLICIT-REFS:ALanguagewithExplicitReferences 104 4.3IMPLICIT-REFS:ALanguagewithImplicitReferences 113 4.4MUTABLE-PAIRS:ALanguagewithMutablePairs 124 4.5Parameter-PassingVariations 130 5 Continuation-PassingInterpreters 139 5.1AContinuation-PassingInterpreter 141 5.2ATrampolinedInterpreter 155 5.3AnImperativeInterpreter 160 5.4Exceptions 171 5.5Threads 179 6 Continuation-PassingStyle 193 6.1WritingProgramsinContinuation-PassingStyle 193 6.2TailForm 203 6.3ConvertingtoContinuation-PassingStyle 212 6.4ModelingComputationalEffects 226 7 Types 233 7.1ValuesandTheirTypes 235 7.2AssigningaTypetoanExpression 238 7.3CHECKED:AType-CheckedLanguage 240 7.4INFERRED:ALanguagewithTypeInference 248 8 Modules 275 8.1TheSimpleModuleSystem 276 8.2ModulesThatDeclareTypes 292 8.3ModuleProcedures 311 9 ObjectsandClasses 325 9.1Object-OrientedProgramming 326 9.2Inheritance 329 9.3TheLanguage 334 9.4TheInterpreter 336 9.5ATypedLanguage 352 9.6TheTypeChecker 358 Contents vii A ForFurtherReading 373 B TheSLLGENParsingSystem 379 B.1Scanning 379 B.2Parsing 382 B.3ScannersandParsersinSLLGEN 383 Bibliography 393 Index 401 Foreword This book brings you face-to-face with the most fundamental idea in com- puterprogramming: Theinterpreter foracomputerlanguageisjustanotherprogram. It sounds obvious, doesn’t it? But the implications are profound. If you are a computational theorist, the interpreter idea recalls Gödel’s discovery of the limitations of formal logical systems, Turing’s concept of a universal computer,andvonNeumann’sbasicnotionofthestored-programmachine. Ifyou area programmer,mastering the ideaof aninterpreterisa sourceof greatpower. It provokes a realshift in mindset, a basic change in the way youthinkaboutprogramming. IdidalotofprogrammingbeforeIlearnedaboutinterpreters,andIpro- duced some substantial programs. One of them, for example, was a large data-entryandinformation-retrievalsystemwritteninPL/I.WhenIimple- mented my system, I viewed PL/I as a fixed collection of rules established bysome unapproachablegroupoflanguagedesigners. Isawmyjob asnot tomodifytheserules,oreventounderstandthemdeeply,butrathertopick through the (very) large manual, selecting this or that feature to use. The notionthattherewassomeunderlyingstructuretothewaythelanguagewas organized, and thatI might want tooverride some of the language design- ers’decisions,neveroccurredtome. Ididn’tknowhowtocreateembedded sublanguages to help organize my implementation, so the entire program seemed like a large, complex mosaic, where each piece had to be carefully shaped and fitted into place, rather than a cluster of languages, where the piecescouldbeflexiblycombined. Ifyoudon’tunderstandinterpreters,you canstillwriteprograms;youcanevenbeacompetentprogrammer.Butyou can’tbeamaster.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.