brookshear 06
TRANSCRIPT
![Page 1: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/1.jpg)
Chapter 6
Programming Languages
![Page 2: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/2.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-2
Chapter 6: Programming Languages
• 6.1 Historical Perspective• 6.2 Traditional Programming Concepts• 6.3 Procedural Units• 6.4 Language Implementation• 6.5 Object Oriented Programming• 6.6 Programming Concurrent Activities• 6.7 Declarative Programming
![Page 3: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/3.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-3
Figure 6.1 Generations of programming languages
![Page 4: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/4.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-4
Second-generation:Assembly language
• A mnemonic system for representing programs– Mnemonic names for op-codes– Names for all registers– Identifiers = descriptive names for memory
locations, chosen by the programmer
![Page 5: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/5.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-5
Assembly language characteristics
• One-to-one correspondence between machine instructions and assembly instructions– Programmer must think like the machine
• Inherently machine-dependent
• Converted to machine language by a program called an assembler
![Page 6: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/6.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-6
Assembly language example
Machine language
156C166D505630CEC000
Assembly language
LD R5, PriceLD R6, ShippingChargeADDI R0, R5 R6ST R0, TotalCostHLT
![Page 7: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/7.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-7
Third generation language
• Uses high-level primitives– Similar to our pseudocode in Chapter 5
• Machine independent (mostly)• Examples: FORTRAN, COBOL• Each primitive corresponds to a short sequence
of machine language instructions• Converted to machine language by a program
called a compiler
![Page 8: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/8.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-8
Figure 6.2 The evolution of programming paradigms
![Page 9: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/9.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-9
Figure 6.3 A function for checkbook balancing constructed from simpler functions
![Page 10: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/10.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-10
Figure 6.4 The composition of a typical imperative program or program unit
![Page 11: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/11.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-11
Figure 6.5 Variable declarations in C, C++, C#, and Java
![Page 12: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/12.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-12
Figure 6.6 A two-dimensional array with two rows and nine columns
![Page 13: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/13.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-13
Figure 6.7 Declaration of heterogeneous array
![Page 14: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/14.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-14
Figure 6.8 Control structures and their representations in C, C++, C#, and Java
![Page 15: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/15.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-15
Figure 6.9 The for loop structure and its representation in C++, C#, and Java
![Page 16: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/16.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-16
Figure 6.10 The flow of control involving a procedure
![Page 17: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/17.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-17
Figure 6.11 The procedure ProjectPopulation written in the programming language C
![Page 18: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/18.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-18
Figure 6.12 Executing the procedure Demo and passing parameters by value
![Page 19: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/19.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-19
Figure 6.13 Executing the procedure Demo and passing parameters by reference
![Page 20: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/20.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-20
Figure 6.14 The function CylinderVolume written in the programming language C
![Page 21: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/21.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-21
Figure 6.15 The translation process
![Page 22: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/22.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-22
Figure 6.16 A syntax diagram of our if-then-else pseudocode statement
![Page 23: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/23.jpg)
6-23
Figure 6.17 Syntax diagrams describing the structure of a simple algebraic expression
![Page 24: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/24.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-24
Figure 6.18 The parse tree for the string x + y x z based on the syntax diagrams in Figure 6.17
![Page 25: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/25.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-25
Figure 6.19 Two distinct parse trees for the statement if B1 then if B2 then S1 else S2
![Page 26: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/26.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-26
Figure 6.20 An object-oriented approach to the translation process
![Page 27: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/27.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-27
Figure 6.21 The complete program preparation process
![Page 28: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/28.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-28
Objects and Classes
• Object = active program unit containing both data and procedures
• Class = a template for all objects of the same type
An Object is often called an instance of the class.
![Page 29: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/29.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-29
Components of an object
• Instance variable = variable within an object
• Method = function or procedure within an object– Can manipulate the object’s instance variables
• Constructor = special method to initialize a new object instance
![Page 30: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/30.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-30
Encapsulation
• Encapsulation = a way of restricting access to the internal components of an object– Private– Public
![Page 31: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/31.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-31
Additional object-oriented concepts
• Inheritance: allows new classes to be defined in terms of previously defined classes
• Polymorphism: allows method calls to be interpreted by the object that receives the call
![Page 32: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/32.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-32
Figure 6.22 The structure of a class describing a laser weapon in a computer game
![Page 33: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/33.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-33
Figure 6.23 A class with a constructor
![Page 34: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/34.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-34
Figure 6.24 Our LaserClass definition using encapsulation as it would appear in a Java or C# program
![Page 35: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/35.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-35
Programming concurrent activities
• Parallel or concurrent processing = simultaneous execution of multiple processes– True concurrent processing requires multiple CPUs– Can be simulated using time-sharing with a single
CPU
![Page 36: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/36.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-36
Interaction between processes
• Mutual exclusion = a method for ensuring that data can be accessed by only one process at a time
• Monitor = a data item augmented with the ability to control access to itself
![Page 37: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/37.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-37
Figure 6.25 Spawning processes
![Page 38: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/38.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-38
Declarative programming
• Resolution = combining two or more statements to produce a new, logically equivalent statement– Example: (P OR Q) AND (R OR Q)
resolves to (P OR R)
– Resolvent = a new statement deduced by resolution– Clause form = statement whose elementary components are
connected by the Boolean operation OR
• Unification = assigning a value to a variable in a statement
![Page 39: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/39.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-39
Figure 6.26 Resolving the statements (P OR Q) and (R OR ¬Q) to produce (P OR R)
![Page 40: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/40.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-40
Figure 6.27 Resolving the statements (P OR Q), (R OR ¬Q), ¬R, and ¬P
![Page 41: Brookshear 06](https://reader036.vdocuments.mx/reader036/viewer/2022081502/554a53d2b4c905572f8b4a85/html5/thumbnails/41.jpg)
© 2005 Pearson Addison-Wesley. All rights reserved6-41
Prolog
• Fact = predicateName(arguments).– Example: parent(bill, mary).
• Rule = conclusion :- premise.– :- means “if”– Example: wise(X) :- old(X).– Example: faster(X,Z) :- faster(X,Y), faster(Y,Z).
• All statements must be fact or rules.