ebook img

Modern Programming Languages: A Practical Introduction PDF

588 Pages·2010·42.428 MB·
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 Modern Programming Languages: A Practical Introduction

MODERN PROGRAMMING LANGUAGES A PRACTICAL INTRODUCTION SECOND EDITION Adam Brooks Webber . Franklin,Beedle& AssociatesInc 22462SWWashingtonSt Sherwood,Oregon97140 503/625-4445 ' www.fbGedle.oom . PresidentandPublisher JimLedsy (jLaiteisy@fljeedteCQEn) Production StephanieWelch TermSumner Assoriatie JamnAyres PrintedintheU5,A, Narniaofallproductsherein,an?used foridentification purposesonlyandaretrademarks and/nrregistered traJemarkHof theirrespectiveowners.franklm,Beedle&.Associates, Inc., makur-inodiiLmof ovvnerslliporcorporateJi^ucintiun withLheproductufcompaniesthat ownthem, ©2011 Franklin, HeedIs?Ik AssociatesIncorporated,Nopartof thishookmayherepro—duced, storedina retrievalsystem,transmitted,ortranscribed,inanyformorbyanymeans elec- tronic,mechanical,telepathic,photooopving,eecurdeng,orotherwise- without priorwritten . permissionot thepublisher Requestsfor permissionshouldbeaddressedasfollows; Rightsand Permissions Franklin,Beadle&Associates,Incorporated 22-162SWWashingtonSt. Sherwood,Oregon97140 - - LibraryofCongressCahiloging Ln PublicationDataisavailablefrom thepublisher, To John Galloway McCubbin 1931-2000 Contents tPMi-l-H-tPfffl'I-t S-TSSi-H-SSS-SS-*“-(cid:127)"(cid:127)(cid:127)iXVll Acknowledgments xxl Chapter1 Programming Languages 1 1.1 Introduction,,, t 1.2 TheAmaz-ngVariety Imperative Languages ,„„„., ,r 2 FunctionalLanguages.. 3 Logic Programming Languages,.. ..... 3 * Object-Oriented Languages 4 „ 1.3 TheOddControversies . . .5 — ii it 1.4 TheIntriguingEvolution .......L-B6 1.5 The ManyConnections,,..., 7 1.6 AWordaboutApplication Programming Interfaces.. ..a 1.7 Conclusion 9 111III!U Chapter2 Defining ProgramSyntax 10 2.1 Introduction .„10 MilIrrMIlI!!! 1*11II 1 1"Ml 2 2 AGrammarExampleforEnglish ....... 11 , 23 A GrammarExampleforaProgramming Language 12 , „ 2.4 A DefinitionolGrammars:Backus-INlaur Form .....13 — 2.5 WritingGrammars..,...,,... 15 2.6 LexicalStructureandPhraseStructure, 17 — 2.7 OtherGr.a..m..mar Forms.rrrr 19 SWF 19 .. ...... . . .................................... IIUIJJI. ILIUJUIUJJ k IB Syntax Diagrams 21 Formal,Contexl4reaGrammars „„..„„„,„.„25 v vi Carttents 2.S Conclusion... » . Exercises 24 FurtherReading 25 Chapter 3 WhereSyntax MeetsSemantics 27 . 3.1 Introduction 27 3.2 Operators,,., ...29 ! . . 3.3 Precedence 29 » 3.4 Associativity 32 .^ 3.5 Other Ambiguities 35 » 3.6 ClutteredGrammars.,.. ,„37 . 3.7 ParseTreesandE6IMF. 36 » 3.8 AbstractSyntaxTrees.. ...39 . 3.9 Conclusion , 40 » Exercises ..rrrr„1TPr ..„41 FurtherReading 42 » Chapter 4 Language Systems 43 . 4.1 IProduction , 43 4.2 TheClassicalSequence ,... ... 43 »»» »»» » Optimization. 48 ..... 4.3 VenationsonSheClassicalSequence 49 HidingtheSteps 49 integratedDevelopmentEnvironments 49 interpreters - 50 VtriuaiMachines 5? DelayedUnking 53 . .. Profiling. ........ ..........................,.—.........—...»................—. ,.,.... 54 DynamicCompilation, , 55 4.4 BlindingTimes 55 Language-DefinitionT/nTe.... ...» 56 Language-implementation77me 5& CompileTi.m.e, . .... ..........56 LinkTime. 56 Loadr/m«-...r , 56 Runtime.. 57 r 4.5 Debuggers4III.L aII|.bJJ1IIa 57 4.6 Runi:pis Support.. ..,............ ............., SB Contents vit 4.7 Conclusion. .59 Exercises 60 Chapter5 A FirstLook atML 65 .. .. St Introduction„ „„rrrr rrri ,...R5 5>2 GellingSlanted1withanMLLanguageSystem ,.,.66 5.3 CtmstanlE 1 ir——-tirppB-i! -- --B ....67 5.4 P6C3toPSIIfc.fcllIIII.-IB|BMB.4414:I IIBBI4JIIBBB44II. 4411 .,....69 5.5 ConditionalExpressions . „ ..70 . 5.6 TypeConversionandFunctionApplication .„.71 5.7 VariableDefinition - — - -- ...73 rr"'ir ""PPII!" "rrpi t 5.8 GarbageCollection 74 5.9 TuplesandLists ....74 5.10 FunctionDefinitions4„ _ -1S'78 5.11 MLTypesandTypeAnnotations, , „„81 Iirra rrprm . 5.12 COnClUSIOflLL.HIILIU44IILLBIJimLIJIIILLIJIIIILB-4 4 LB83 . . . LKt^rCJS.ib.r,"irirrr--,, -irrr---i *,------ ,„03 .. FurtherReading .8S 4 Chapters Types 86 6.I1 Introduction ... B6 6.2 AMenaqcneofTypes 87 ATypeis3Set. S7 PrimitiveTypesandGonsfrijctetiTypes s& BnumemUcns r.,, Tuples 50 Arrau'S Sinners andLists 92 Unions 93 r Subtypes, 55 PunrtinnTi/nns . , 96 6.3 U^sforType* 97 97 Typeinference „.98 t TypsChecking PR - TypeEquri/afenceissues 100 6.4 COflCilJSIQflk|IBJJ1lf.piAJ.1kklllilkkBkld11kkkIJB1kkBBBJBkl.BBiJB11GBJJ iikkiBJBiibuaiBkkBiJi.LL444.101 Exsidsas „ .... .......102 VIII Carttents Chapter 7 A Second Lookat ML 103 7.1 Introduction ... .... ... 103 7.2 PatternsYouAlfeadyKnow 103 7.3 MoreSimplePatterns 104 7.4 ComplexPatterns 105 7.5 ASummaryolMlPatternsSoFar 106 7.6 UsingMultiplePatternsforFunctions 106 7.7 Pattern-MatchingStyle...-......................... 10^ .. ... .... 7.8 LocalVariableDefinitions, „„ . 110 7.9 NestedFunctionDefinitions 114 7.10 Conclusion — ,115 » Exercises 11S ! Chapter8 Polymorphism 118 0.1 Introduction 11ft 8.2 Overloading............... ...... . 1T9 0.3 ParameterCoercion . 8.4 ParametricPolymorphism 124 0.5 SubtypoPolymorphism 126 8.6 Conclusion..., ... 120 Exerdsos .„.„. „„ „, 130 prfcm>f rp vprpr FurtherReading....... ................ ..„132 Chapter 9 AThirdLookat ML 133 9.1 introduction .„.133 9.2 134 . 9.3 FunctionValuesan<jAnonymousFunctions 135 .. 9.4 Higher-OrderFunctionsandCurrying... J!.« J..LLBiaJi.i.m.--.. 137 9.6 pjfSdBflfcftdHigher-OuterFunctions 140 17»mapFunction. .................... .... 140 . ... Fhetaldr Function, ... . 14? Th&Foldl Function 143 9.6 Conclusion „ .... ...._143 EExercisGs — , —,,, ,., — — - ...144 r § i (cid:127)r BH P Contents lx Chapter10 Scope 140 10.1 Introduction 148 10.2 DefinitionsandScope 149 10.0 ScopingwitnBlocks irp--fvrrppmi -«-(cid:127)i115»1 10.4 ScopingwithLabeledNamespaces,.......... 154 10-5 ScopingwithPnmiiiveNamespaces 157 106 DynamicScoping.. 159 10.7 AWordaboutSeparateCompilation.. . 161 ioa Conclusion. , .... .... . .... ..162 Exercises ,, 162 . FurtherReading,.. 164 Chapter11 AFourth Look at ML 105 ... 11.1 introduction 165 . . 11.2 Enumerations . 166 113 DataConstructorswtflhParamete*rs.., .„..167 . 11.4 TypeConstructorswrthParameters ..169 ...... ... 11.5 RecursivelyDefinedTypeConstructors 171 — 11.6 Conclusion FarewelllaML ...176 . ... .. . ...... ... E 177 Ii IIiireiirrniiii iiirill Iirinii r FurtherReading ..179 * Chapter12 MemoryLocationsfor Variables 101 liSs'tl Introduction ..101 milIIIIliai III !iIkhmiii :iik 12.2 Activation-SpecificVariables .„.102 OtherKindsofVariables 1&3 12.3 ActivationRecords.. - 184 +i 12.4. Static Allocationor ActivationRecords„ .185 — 12.5 DynamicStacksotActivationRecords.„. mmm-mmmm...8.187 126 Handling testedFunctionDefinitions,,. 194 12.7 FunctionsasParameters ,.,198 12.0 Long-LivedFunctions „„ ...*.200 12.9 Conclusion - ....202 ...... ... Exercises , 203 r X Carttents Chapter 13 AFirstLookatJava 205 13.1 !nlroduction 205 13.2 ThinkingaboutObjects . . 206 13.3 SimpleExpressionsandStatements , ...208 ConstantsandTypes 208 OperatorsforIntegerArithmetic. 210 . OperatorsforRealArithmetic 21Q - ConcatenationpfStrings,,, J . ComparisonOperators 211 BooleanOperators 212 . . OperatorswithSideEffects ,...212 OMbejtehccttdCGreaaittsio,,Pn.„Expressions.. .............. 221186 Associativity Precedence. Coercion,andAMThat 218 ExpressionStatements,...........,...........................219 CompoundStatements 220 DeclarationStatements . „...221 . Theif Statement 222 .. Thewhile Statements ..................222 ThereturnStatement... 223 13.4 ClassDefinitions,, 223 13.5 About ReferencesandFormers ..229 13.6 GettingStarredwilhaJavaLanguageSystem ....231 13.7 Conclusion.. .,..233 Exercises 233 FurtherReading.kk..4J-.. .....236 Chapter 14 MemoryManagement 237 14.1 Inlroduction 237 14.2 AMemoryModelUsingJavaArrays... - 238 14.3 Slacks , 240 14.4 Heaps .,.244 AFirst-FitMechanism ...........245 . CoalescingFreeBlocks, 250 QuickListsandDelayedCoalescing 252 Fragmentation....,rirrr„,,rrr..,rrrP,,,,„„„„„„„rrP.,.r.rr,.,254 OtherHeapMechanisms ...... 255 14.5 CurrentHeapLinks 257 TmcingCurrentHeapLinks. 257

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.