Concepts of Programming Languages: a Unified Approach

Concepts of Programming Languages: a Unified Approach

Concepts of Programming Languages: A Unified Approach Karl Abrahamson August 2011 2 Copyright (c) 2011 Karl Abrahamson. Contents I Fundamental Concepts 17 1 Introduction to Programming Languages 19 2 Language Classification 21 2.1 Imperativeprogramming. .. 21 2.2 Declarativeprogramming . .. 22 2.3 Languageclassification . ... 23 2.4 Summaryofterminologyandconcepts . .... 24 2.5 Exercises...................................... 25 2.6 Bibliographicnotes.............................. .. 25 3 Encapsulation and Information Hiding 27 3.1 Encapsulationandmodification . .... 27 3.2 Somekindsofencapsulations . ... 27 3.3 Intensionandextension . .. .. .. .. .. .. .. .. .. .. .. .. 28 3.4 Languagesupport................................. 28 3.5 Summaryofterminologyandconcepts . .... 29 3.6 Exercises...................................... 30 4 Implementation of Programming Languages 31 4.1 Compilers ..................................... 31 4.2 Linkers....................................... 31 4.3 Interpreters .................................... 32 4.4 Comparisonofcompilersandinterpreters . ....... 33 4.5 Hybridimplementations . .. 34 4.6 Librariesandrun-timesupport . .... 35 4.7 Languages are not their implementations . ....... 35 4.8 Summaryofterminologyandconcepts . .... 37 4.9 Exercises...................................... 38 4.10 Bibliographicnotes . .. .. .. .. .. .. .. .. .. .. .. .. ... 39 II Syntax and Semantics 41 5 Form and Function 43 5.1 Thesyntaxofalanguage ............................ 43 5.2 Formsuggestsfunction.. .. .. .. .. .. .. .. .. .. .. .. .. 43 3 4 CONTENTS 5.3 Summaryofterminologyandconcepts . .... 45 5.4 Exercises...................................... 45 5.5 Bibliographicnotes.............................. .. 46 6 Describing Syntax and Structure 47 6.1 Describingthesyntaxofalanguage. ..... 47 6.2 Lexicalrules.................................... 47 6.3 Programstructureandparsetrees . .... 49 6.4 Using grammars to indicate allowed trees . ...... 51 6.5 Commongrammaticalforms. 52 6.6 Ambiguity..................................... 53 6.7 Syntaxisnotmeaning .............................. 56 6.8 ExtendedBNFnotation ............................. 56 6.9 Syntaxdiagrams ................................. 57 6.10 Summaryofterminologyandconcepts . ..... 59 6.11 Exercises...................................... 60 6.12 Bibliographicnotes . .. .. .. .. .. .. .. .. .. .. .. .. ... 62 7 Semantics 63 7.1 Introductiontosemantics . ... 63 7.2 Operationalsemantics ............................ .. 63 7.3 Denotationalsemantics. ... 63 7.4 Axiomaticsemantics .............................. 64 7.5 Partialsemantics ................................ 64 7.6 Relationalsemantics ............................. .. 65 7.7 Semantic black holes and infinite loops . ...... 65 7.8 Resourcelimitationsandsemantics . ...... 66 7.9 Summaryofterminologyandconcepts . .... 66 7.10 Exercises...................................... 67 7.11 Bibliographicnotes . .. .. .. .. .. .. .. .. .. .. .. .. ... 68 III Managing Information 69 8 Data and Data Representation 71 8.1 Programsanddata................................ 71 8.2 Simplevalues ................................... 71 8.3 Tuplesandrecords ................................ 72 8.4 Listsandarrays.................................. 73 8.5 Sets ........................................ 77 8.6 Trees........................................ 77 8.7 Tables ....................................... 79 8.8 Tagsandtaggedvalues............................. 79 8.9 Firstclassdataitems............................. .. 80 8.10 Objects ...................................... 81 8.11 Persistentandephemeraldata. ..... 81 8.12 Summaryofterminologyandconcepts . ..... 82 8.13 Exercises...................................... 83 CONTENTS 5 8.14 Bibliographicnotes . .. .. .. .. .. .. .. .. .. .. .. .. ... 86 9 Data Types 89 9.1 Types ....................................... 89 9.2 Sourcesoftypeinformation . ... 89 9.3 Typechecking................................... 90 9.4 Typesassets ................................... 92 9.5 Anotationfortypes ............................... 92 9.6 Subtypes...................................... 94 9.7 Summaryofterminologyandconcepts . .... 95 9.8 Exercises...................................... 97 9.9 Bibliographicnotes.............................. .. 97 10 Memory Management 99 10.1 Memoryallocation ............................... 99 10.2 Staticallocation............................... ... 99 10.3 Dynamic allocation: the run-time stack . ........100 10.4 Dynamicallocation:theheap . .101 10.5 Garbagecollection .............................. 103 10.6 Summaryofterminologyandconcepts . .105 10.7 Exercises...................................... 106 10.8 Bibliographicnotes . .. .. .. .. .. .. .. .. .. .. .. .. .107 IV Names, Scope and Modules 109 11 Names and Name Binding 111 11.1 Givingthingsnames .............................. 111 11.2 Identifiers ..................................... 111 11.3 Namingdataitems ................................ 111 11.4 Namingandcreation .............................. 112 11.5 Namesintheimplementation . .113 11.6 Overloading.................................... 114 11.7 Patternmatching................................ 114 11.8 Summaryofterminologyandconcepts . .115 11.9 Exercises...................................... 116 11.10 Bibliographicnotes . .117 12 Scope, Visibility and Modules 119 12.1 Limitingscope .................................. 119 12.2 Thescopeofabinding: smallscale . .119 12.3 Thescopeofabinding: largescale . .122 12.4 Namingonalargescale ............................ 125 12.5 Summaryofterminologyandconcepts . .126 12.6 Exercises...................................... 127 12.7 Bibliographicnotes . .. .. .. .. .. .. .. .. .. .. .. .. .128 6 CONTENTS 13 Mechanics of the Run-Time Stack 129 13.1 Activations .................................... 129 13.2 Pushingandpoppingframes. .129 13.3 Scopeandclosures ............................... 130 13.4 Tailrecursionandtailcalls . .132 13.5 Summaryofterminologyandconcepts . .134 13.6 Exercises...................................... 137 13.7 Bibliographicnotes . .. .. .. .. .. .. .. .. .. .. .. .. .138 V Imperative Programming 139 14 Structured Programming 141 14.1 Imperativeprogramming. .141 14.2 Statements,variablesandassignment . ........142 14.3 Control:earlyapproaches . .142 14.4 Structuredprogrammingconstructs. .......144 14.5 Variationsonchoice ............................. 146 14.6 Variationsonloops .............................. 148 14.7 Summaryofterminologyandconcepts . .149 14.8 Exercises...................................... 152 14.9 Bibliographicnotes . .. .. .. .. .. .. .. .. .. .. .. .. .153 15 Objects and First Class Variables 155 15.1 Variablesasdataitems. .155 15.2 Expressioncontext: lvalueandrvalue. ........156 15.3 Extendingcontexttoaggregates. .. ..157 15.4 Summaryofterminologyandconcepts . .159 15.5 Exercises...................................... 160 16 Procedures and Parameter Passing 161 16.1 Proceduralprogramming. .161 16.2 Informationflow ................................. 161 16.3 Recursion .....................................163 16.4 Syntactic approaches to parameter passing . .........163 16.5 Parameterpassingmodes . 164 16.6 Call-by-reference .............................. .166 16.7 Copyinginandout................................ 167 16.8 Summaryofterminologyandconcepts . .168 16.9 Exercises...................................... 169 16.10 Bibliographicnotes . .170 VI Elementary Functional Programming 171 17 Introduction to Functional Programming 173 17.1 Functionalprogramming . .173 17.2 Functionalprogramminginthisbook. .. ..173 17.3 Functionalprogramminglanguages . .. ..174 CONTENTS 7 17.4 Summary .....................................174 17.5 Bibliographicnotes . .. .. .. .. .. .. .. .. .. .. .. .. .174 18 Computing with Equations 177 18.1 Functionsandequations . .177 18.2 Makingdecisions ................................ 177 18.3 Recursion .....................................178 18.4 Patternmatching................................ 178 18.5 Theformofanequationalprogram . .180 18.6 Themechanicsofsubstitution . .180 18.7 Evaluationpolicies . .. .. .. .. .. .. .. .. .. .. .. .. .181 18.8 Equationalprogrammingwithlists . .. ..182 18.9 Summaryofterminologyandconcepts . .184 18.10 Exercises..................................... 186 18.11 Bibliographicnotes . .187 19 Are Imperative Constructs Necessary? 189 19.1 Introduction................................... 189 19.2 Persistentdatastructures . .189 19.3 Loopsandequationaldefinitions . .190 19.4 Summaryofterminologyandconcepts . .193 19.5 Exercises...................................... 193 20 Equational Programming in Cinnameg 197 20.1 Defining functions in Cinnameg . .197 20.2 Writingexamples ................................ 198 20.3 Searchorder.................................... 198 20.4 Givingthingsnames .............................. 199 20.5 Types .......................................199 20.6 Listnotations.................................. 201 20.7 Testingyourdefinitions . .202 20.8 Exercises...................................... 204 20.9 Bibliographicnotes . .. .. .. .. .. .. .. .. .. .. .. .. .204 VII Exploring Functional Programming 205 21 Higher-Order Functional Programming 207 21.1 Functionsasvalues .............................. 207 21.2 Functionexpressions . .207 21.3 The mechanics of function application . .......208 21.4 Functiontransformers . .208 21.5 Curriedfunctions ............................... 209 21.6 Typesoffunctions ..............................

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    597 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us