Programming Language

By Michele Podmore

Chapter 1 Introduction ......................................................................................... 1 Program Example ...................................................................................... 1 Approximate Numbers .............................................................................. 4 Formal and Natural Languages ................................................................. 9 Glossary .................................................................................................... 11 Chapter 2 Preliminary Concepts of Programming Language.......................... 13 Character Classification........................................................................... 13 Lists.......................................................................................................... 14 List Values ............................................................................................... 14 Accessing Elements................................................................................. 15 List Length ............................................................................................... 16 List Membership ...................................................................................... 16 Lists and for Loops .................................................................................. 17 List Operations ........................................................................................ 18 List Slices ................................................................................................. 18 Lists are Mutable ..................................................................................... 18 List Deletion ............................................................................................ 19 Objects and Values .................................................................................. 19 Aliasing .................................................................................................... 20 Cloning Lists ............................................................................................ 21 List Parameters ....................................................................................... 21 Nested Lists ............................................................................................. 22 Matrices ................................................................................................... 23 vi Strings and Lists ...................................................................................... 23 Glossary ................................................................................................... 24 Mutability and Tuples ............................................................................... 24 Tuple Assignment..................................................................................... 25 Tuples as Return Values .......................................................................... 26 Programming Language and Tools .......................................................... 26 Compound Data Type .............................................................................. 26 Length ...................................................................................................... 27 Traversal and the for Loop ...................................................................... 27 String Slices ............................................................................................. 28 String Comparison.................................................................................... 29 Strings are Immutable .............................................................................. 30 A Find Function........................................................................................ 30 Random Numbers .................................................................................... 30 List of Random Numbers ........................................................................ 31 Counting ................................................................................................... 32 Many Buckets .......................................................................................... 33 A Single-pass Solution.............................................................................. 34 Glossary ................................................................................................... 35 Dictionaries .............................................................................................. 35 Dictionary Operations .............................................................................. 36 Dictionary Methods ................................................................................. 37 Aliasing and Copying ............................................................................... 38 Sparse Matrices ....................................................................................... 38 Hints ......................................................................................................... 39 Long Integers ........................................................................................... 40 Counting Letters ...................................................................................... 41 Glossary ................................................................................................... 42 Files and Exceptions ................................................................................ 42 Text Files .................................................................................................. 44 Writing Variables ...................................................................................... 45 Directories ............................................................................................... 47 Pickling..................................................................................................... 47 Exceptions ................................................................................................ 48 Glossary ................................................................................................... 50 Looping and Counting .............................................................................. 50 The String Module ................................................................................... 51 Chapter 3 C Language Programming ................................................................ 52 Introduction .............................................................................................. 52 C (Programming Language) .................................................................... 53 What Comprises a C Programme? .......................................................... 54 Structure of a C Programme ................................................................... 55 vii Programming Examples ........................................................................... 63 First Example ........................................................................................... 63 Second Example ...................................................................................... 66 Statement and Control ............................................................................. 68 Expression Statements ............................................................................. 68 If Statements ........................................................................................... 69 Program Structure ................................................................................... 72 Data Types and Operators ...................................................................... 75 Types ........................................................................................................ 75 Constants ................................................................................................. 76 Declarations ............................................................................................. 77 Variable Names ....................................................................................... 79 Arithmetic Operators ............................................................................... 79 Assignment Operators ............................................................................. 80 Function Calls .......................................................................................... 81 Chapter 4 Computer Programmes and Programming Languages .................. 82 Development of Computers ..................................................................... 83 Analog Computers ................................................................................... 83 Computer Organization ............................................................................ 84 Processors and Memory .......................................................................... 84 Instruction Format.................................................................................... 86 Computer Data Storage ........................................................................... 87 Computer Architecture ............................................................................ 88 History of Architecture ............................................................................ 90 Computer Architecture Topics ................................................................. 91 The Role of Computer Architecture ........................................................ 91 Computer Memory .................................................................................. 94 History ..................................................................................................... 95 Volatile Memory Computer Memory ....................................................... 96 Chapter 5 Language Orientation Programming ............................................... 99 Class Variables/Methods ....................................................................... 100 Reflection ............................................................................................... 100 Access Control ...................................................................................... 100 Design by Contract ................................................................................ 101 Static vs. Dynamic Typing ..................................................................... 102 Operator Overloading ............................................................................ 103 Higher Order Functions ......................................................................... 104 Garbage Collection ................................................................................ 105 Uniform Access ..................................................................................... 106 Generic Classes ..................................................................................... 107 Inheritance ............................................................................................. 107 viii Chapter 6 Expressions and Statements .......................................................... 110 Variables and Expressions ...................................................................... 110 Values and Types .................................................................................... 110 Variables ................................................................................................. 111 Variable Names and Keywords .............................................................. 112 Statements .............................................................................................. 113 Evaluating Expressions ........................................................................... 113 Operators and Operands ........................................................................ 114 Order of Operations................................................................................ 114 Operations on Strings .............................................................................. 115 Composition............................................................................................. 115 Comments ............................................................................................... 116 Statements .............................................................................................. 116 Simple and Compound Statements.......................................................... 117 The if Statement ..................................................................................... 118 Else if Statement .................................................................................... 121 Switch Statement ................................................................................... 121 While Statement .................................................................................... 123 Do Statement ......................................................................................... 124 For Statement ........................................................................................ 125 Continue Statement ................................................................................ 128 Break Statement .................................................................................... 129 Goto Statement ...................................................................................... 130 Return Statement ................................................................................... 130 Chapter 7 Logic Programming Language and Structure ............................... 132 Logic Programming ............................................................................... 132 Programming Structure .......................................................................... 143 Identifiers ............................................................................................... 147 Variables ................................................................................................ 150 Strings .................................................................................................... 152 Chapter 8 Basic Concept of Object-Oriented Programming ........................ 195 Real Tool ................................................................................................ 195 Objects ................................................................................................... 195 Class ...................................................................................................... 196 Inheritance ............................................................................................. 196 Interface ................................................................................................ 196 Package ................................................................................................. 196 Definition................................................................................................ 197 COM...................................................................................................... 197 Component-based Development (CBD) ................................................ 198 Advantages of COM ............................................................................. 198 ix COM Interfaces .................................................................................... 199 Interface Definition Language (IDL) .................................................... 200 Windows Registry and Components ...................................................... 201 Creating a COM object ......................................................................... 202 LockServer ............................................................................................ 202 Object-Oriented Language Features ..................................................... 203 Why Object-Oriented Database ............................................................ 203 Strategy for Defining Immutable Objects .............................................. 203 High Level Concurrency Objects .......................................................... 204 Lock Objects .......................................................................................... 205 Executors ............................................................................................... 207 Executor Interfaces ............................................................................... 208 Thread Pools .......................................................................................... 209 Fork/Join ................................................................................................ 209 Object-Oriented Programming .............................................................. 212 Object Entity .......................................................................................... 212 Abstraction ............................................................................................. 212 Encapsulation ......................................................................................... 213 Inheritance ............................................................................................. 213 Polymorphism......................................................................................... 213 Example ................................................................................................. 214 Simple Input/Output ............................................................................... 217 Annotation .............................................................................................. 217 Annotation .............................................................................................. 218 Comments .............................................................................................. 218 Memory.................................................................................................. 219 Classes and Objects in Programming .................................................... 220 User-defined Compound Types ............................................................. 220 Attributes ............................................................................................... 221 Instances as Arguments ......................................................................... 222 Sameness ............................................................................................... 222 Instances as Return Values ................................................................... 223 Objects are Mutable .............................................................................. 223 Copying .................................................................................................. 224 Sets of Objects ...................................................................................... 225 Composition............................................................................................ 225 Card Objects .......................................................................................... 225 Class Attributes and the __str__ method .............................................. 226 Comparing Cards ................................................................................... 227 Decks ..................................................................................................... 228 Printing the Deck ................................................................................... 228 Shuffling the Deck ................................................................................. 230 Removing and Dealing Cards ................................................................ 231 x Classes and Functions............................................................................ 231 Time ....................................................................................................... 231 Pure Functions ....................................................................................... 232 Modifiers ................................................................................................ 233 Prototype Development ......................................................................... 234 Generalization ........................................................................................ 235 Algorithms .............................................................................................. 235 Classes and Methods ............................................................................. 236 Object-oriented Features ....................................................................... 236 Print Time............................................................................................... 237 Another Example ................................................................................... 238 Example ................................................................................................. 238 Optional Arguments ............................................................................... 239 The Initialization Method ....................................................................... 240 Points Revisited ..................................................................................... 241 Operator Overloading ............................................................................ 241 Polymorphism......................................................................................... 243 Chapter 9 Statements and Language Programming....................................... 245 Characters ............................................................................................. 248 Objects ................................................................................................... 249 Integer Data Type.................................................................................. 255 Float Data type ...................................................................................... 255 Assignment Operator ............................................................................. 256 Conditional Operator .............................................................................. 257 Comma Operator ................................................................................... 257 Size of Operator .................................................................................... 258 Operator Precedence ............................................................................ 258 Simple Type Conversion ........................................................................ 259 Strings .................................................................................................... 259 Names .................................................................................................... 260 Operators and Expressions .................................................................... 261 Arithmetic Operators ............................................................................. 261 Relational Operators .............................................................................. 262 Logical Operators .................................................................................. 262 Bitwise Operators .................................................................................. 263 Increment/Decrement Operators .......................................................... 264 Variables ................................................................................................ 265 Annotation .............................................................................................. 265 Initialization ............................................................................................ 266 Memory.................................................................................................. 267 Defined Data Types (typedef) ............................................................... 267 xi Enumerations (enum) ............................................................................. 270 Classes (I) .............................................................................................. 271 Chapter 10 Functional Ways of Programming Language................................. 272 Introduction ............................................................................................ 272 Python Programming Language ............................................................ 272 Program ................................................................................................. 274 Debugging .............................................................................................. 274 Function Basics of Programming ........................................................... 276 Function Prototypes ............................................................................... 279 Function Philosophy ............................................................................... 279 Separate Compilation Logistics .............................................................. 281 Fruitful Functions ................................................................................... 283 Return Values ........................................................................................ 283 Composition............................................................................................ 284 Boolean Functions.................................................................................. 285 More Recursion ..................................................................................... 285 Leap of Faith ......................................................................................... 287 Checking Types ..................................................................................... 287 Iteration and Multiple Assignment ......................................................... 288 The While Statement ............................................................................. 289 Two-dimensional Tables......................................................................... 291 Encapsulation and Generalization .......................................................... 291 More Encapsulation ............................................................................... 292 Local Variables ...................................................................................... 292 More Generalization............................................................................... 293 Conditionals and Recursion.................................................................... 295 The Modulus Operator .......................................................................... 295 Boolean Expressions .............................................................................. 295 Logical Operators .................................................................................. 296 Conditional Execution ............................................................................ 296 Alternative Execution ............................................................................ 297 Chained Conditionals ............................................................................. 297 Nested Conditionals ............................................................................... 298 The Return Statement............................................................................ 299 Recursion ............................................................................................... 299 Stack Diagrams for Recursive Functions .............................................. 300 Infinite Recursion................................................................................... 301 Keyboard Input ...................................................................................... 301 Functions ................................................................................................ 302 Function Calls ........................................................................................ 302 Type Conversion .................................................................................... 303 Type Coercion ....................................................................................... 303 Math Functions ...................................................................................... 304 Composition............................................................................................ 305 Adding New Functions .......................................................................... 305 Code Fragmentation............................................................................... 306 Flow of Execution .................................................................................. 307 Parametres and Arguments ................................................................... 308 Variables and Parametres are Local ...................................................... 309 Stack Diagrams ..................................................................................... 309 Functions with Results ........................................................................... 310 Chapter 11 Arrays Programming Language ..................................................... 311 Array Initialization.................................................................................. 314 Multidimensional Arrays ........................................................................ 314 Multidimensional Arrays and Functions ................................................. 316 Dynamically Allocating Multidimensional Arrays .................................. 318 Dynamic Arrays in Assembly Language ............................................... 320 Arrays of Structures .............................................................................. 325 Single Dimension Arrays ....................................................................... 326 Structures of Structures ......................................................................... 327 Character Arrays ................................................................................... 328 Concept of Arrays ................................................................................. 329 In Dis-array............................................................................................ 330 Initialization of Arrays ............................................................................ 331 Initialization of Character Arrays ........................................................... 332 Initialization of Multidimensional Arrays ................................................ 333 Rows and Tables ................................................................................... 335 Using Arrays .......................................................................................... 336 Limits and Dimension of Array .............................................................. 337 Arrays and for loops .............................................................................. 338 Arrays of More than One Dimension .................................................... 340 Arrays and Nested Loops ...................................................................... 342 Initializing Arrays ................................................................................... 342 Arrays and Pointers ............................................................................... 343 Arrays as Parameters............................................................................ 344

ISBN978-93-6363-971-3
Copyright Year2026
Pages364
Price$ 275
LanguageEnglish
FormatPDF