Copyright © 2015 Pearson Education, Inc. Chapter 6: Programming Languages.

Slides:



Advertisements
Similar presentations
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Advertisements

Programming Languages and Paradigms
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
High-Level Programming Languages
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Programming Languages Structure
Programming Languages
Chapter 8 High-Level Programming Languages Nell Dale John Lewis.
Programming Languages – Coding schemes used to write both systems and application software A programming language is an abstraction mechanism. It enables.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
Imperative Programming
High-Level Programming Languages: C++
Chapter 8 High-Level Programming Languages. 2 Compilers High-level language A language that provides a richer (more English like) set of instructions.
CIS Computer Programming Logic
Introduction Computer science is the discipline that seeks to build a scientific foundation for a variety of topics. Computer science provides the underpinnings.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
AS Computing Introduction to Programming. What is a Computer Program? A list of instructions that a computer must work through, in a logical sequence,
Programming Languages: History & Traditional Concepts CSC 2001.
1 Introduction Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
Computer Concepts 2014 Chapter 12 Computer Programming.
Chapter 9 Programming Languages
Chapter 6 Programming Languages. © 2005 Pearson Addison-Wesley. All rights reserved 6-2 Chapter 6: Programming Languages 6.1 Historical Perspective 6.2.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Lecture on Programming Languages
Computer Programs and Programming Languages What are low-level languages and high-level languages? High-level language Low-level language Machine-dependent.
Chapter 6 Programming Languages © 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Programming Languages and Paradigms Imperative Programming.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
Chapter 3 Part II Describing Syntax and Semantics.
Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Chapter 8 High-Level Programming Languages. 2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Object Oriented Software Development 4. C# data types, objects and references.
Chapter 9 ProgrammingLanguages.  Describe the evolution of programming languages from machine language to high-level languages.  Understand how a program.
CPS120: Introduction to Computer Science Variables and Constants.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Programming Languages Salihu Ibrahim Dasuki (PhD) CSC102 INTRODUCTION TO COMPUTER SCIENCE.
Computer Programming - Key Concepts and Terms Computer Program – A computer program is a set of instructions for computer, arranged in logical order, using.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Information and Computer Sciences University of Hawaii, Manoa
Ch. 7 Programming Languages
Computer Programming.
Chapter 6: Programming Languages
CSCE Fall 2013 Prof. Jennifer L. Welch.
Elements of Programming Languages
High Level Programming Languages
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Chapter 6: Programming Languages
CSCE Fall 2012 Prof. Jennifer L. Welch.
Overview of Programming Paradigms
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Presentation transcript:

Copyright © 2015 Pearson Education, Inc. Chapter 6: Programming Languages

Copyright © 2015 Pearson Education, Inc. 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 Chapter 6: Programming Languages 6-2

Copyright © 2015 Pearson Education, Inc. Figure 6.1 Generations of programming languages 6-3

Copyright © 2015 Pearson Education, Inc. A mnemonic system for representing machine instructions –Mnemonic names for op-codes –Program variables or identifiers: Descriptive names for memory locations, chosen by the programmer Second-generation: Assembly language 6-4

Copyright © 2015 Pearson Education, Inc. 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 Assembly Language Characteristics 6-5

Copyright © 2015 Pearson Education, Inc. Program Example Machine language 156C 166D CE C000 Assembly language LD R5, Price LD R6, ShipCharge ADDI R0, R5 R6 ST R0, TotalCost HLT 6-6

Copyright © 2015 Pearson Education, Inc. Uses high-level primitives –Similar to our pseudocode in Chapter 5 Machine independent (mostly) Examples: FORTRAN, COBOL Each primitive corresponds to a sequence of machine language instructions Converted to machine language by a program called a compiler Third Generation Language 6-7

Copyright © 2015 Pearson Education, Inc. Figure 6.2 The evolution of programming paradigms 6-8

Copyright © 2015 Pearson Education, Inc. Figure 6.3 A function for checkbook balancing constructed from simpler functions 6-9

Copyright © 2015 Pearson Education, Inc. Figure 6.4 The composition of a typical imperative program or program unit 6-10

Copyright © 2015 Pearson Education, Inc. Integer: Whole numbers Real (float): Numbers with fractions Character: Symbols Boolean: True/false Data Types 6-11

Copyright © 2015 Pearson Education, Inc. float Length, Width; int Price, Total, Tax; char Symbol; int WeightLimit = 100; Variables and Data types 6-12

Copyright © 2015 Pearson Education, Inc. Data Structure 6-13 Conceptual shape or arrangement of data A common data structure is the array –In C int Scores[2][9]; –In FORTRAN INTEGER Scores(2,9)

Copyright © 2015 Pearson Education, Inc. Figure 6.5 A two-dimensional array with two rows and nine columns 6-14

Copyright © 2015 Pearson Education, Inc. Figure 6.6 The conceptual structure of the aggregate type Employee 6-15 struct { char Name[25]; int Age; float SkillRating; } Employee;

Copyright © 2015 Pearson Education, Inc. In C, C++, C#, Java Z = X + y; In Ada Z := X + y; In APL (A Programming Language) Z ← X + y Assignment Statements 6-16

Copyright © 2015 Pearson Education, Inc. Go to statement goto Evade() goto if (KryptoniteLevel < LethalDose) then goto 60 goto RescueDamsel() As a single statement if (KryptoniteLevel < LethalDose): RescueDamsel() else: Evade() Control Statements 6-17

Copyright © 2015 Pearson Education, Inc. If in Python if (condition): statementA else: statementB In C, C++, C#, and Java if (condition) statementA; else statementB; In Ada IF condition THEN statementA; ELSE statementB; END IF; Control Statements (continued) 6-18

Copyright © 2015 Pearson Education, Inc. While in Python while (condition): body In C, C++, C#, and Java while (condition) { body } In Ada WHILE condition LOOP body END LOOP; Control Statements (continued) 6-19

Copyright © 2015 Pearson Education, Inc. Switch statement in C, C++, C#, and Java switch (variable) { case 'A': statementA; break; case 'B': statementB; break; case 'C': statementC; break; default: statementD; } In Ada CASE variable IS WHEN 'A'=> statementA; WHEN 'B'=> statementB; WHEN 'C'=> statementC; WHEN OTHERS=> statementD; END CASE; Control Statements (continued) 6-20

Copyright © 2015 Pearson Education, Inc. Figure 6.7 The for loop structure and its representation in C++, C#, and Java 6-21

Copyright © 2015 Pearson Education, Inc. Explanatory statements within a program Helpful when a human reads a program Ignored by the compiler /* This is a comment. */ // This is a comment Comments 6-22

Copyright © 2015 Pearson Education, Inc. Many terms for this concept: –Subprogram, subroutine, procedure, method, function Unit begins with the function’s header Local versus Global Variables Formal versus Actual Parameters Passing parameters by value versus reference Procedural Units 6-23

Copyright © 2015 Pearson Education, Inc. Figure 6.8 The flow of control involving a function 6-24

Copyright © 2015 Pearson Education, Inc. Figure 6.9 The function ProjectPopulation written in the programming language C 6-25

Figure 6.10 Executing the function Demo and passing parameters by value

Figure 6.11 Executing the function Demo and passing parameters by reference

Copyright © 2015 Pearson Education, Inc. Figure 6.12 The fruitful function CylinderVolume written in the programming language C 6-28

Copyright © 2015 Pearson Education, Inc. Figure 6.13 The translation process 6-29

Copyright © 2015 Pearson Education, Inc. Figure 6.14 A syntax diagram of Python’s if-then-else statement 6-30

Copyright © 2015 Pearson Education, Inc. Figure 6.15 Syntax diagrams describing the structure of a simple algebraic expression 6-31

Copyright © 2015 Pearson Education, Inc. Figure 6.16 The parse tree for the string x + y * z based on the syntax diagrams in Figure

Figure 6.17 Two distinct parse trees for the statement if B1 then if B2 then S1 else S2

Copyright © 2015 Pearson Education, Inc. Figure 6.18 An object-oriented approach to the translation process 6-34

Copyright © 2015 Pearson Education, Inc. Object: Active program unit containing both data and procedures Class: A template from which objects are constructed An object is called an instance of the class. Objects and Classes 6-35

Copyright © 2015 Pearson Education, Inc. Figure 6.19 The structure of a class describing a laser weapon in a computer game 6-36

Copyright © 2015 Pearson Education, Inc. Instance Variable: Variable within an object –Holds information within the object Method: Procedure within an object –Describes the actions that the object can perform Constructor: Special method used to initialize a new object when it is first constructed Components of an Object 6-37

Copyright © 2015 Pearson Education, Inc. Figure 6.21 A class with a constructor 6-38

Copyright © 2015 Pearson Education, Inc. Encapsulation: A way of restricting access to the internal components of an object –Private –Public Object Integrity 6-39

Copyright © 2015 Pearson Education, Inc. Figure 6.22 Our LaserClass definition using encapsulation as it would appear in a Java or C# program 6-40

Copyright © 2015 Pearson Education, Inc. 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 Additional Object-oriented Concepts 6-41

Copyright © 2015 Pearson Education, Inc. 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 Programming Concurrent Activities 6-42

Copyright © 2015 Pearson Education, Inc. Figure 6.23 Spawning threads 6-43

Copyright © 2015 Pearson Education, Inc. 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 Controlling Access to Data 6-44

Copyright © 2015 Pearson Education, Inc. Resolution: Combining two or more statements to produce a new statement (that is a logical consequence of the originals). –Example: (P OR Q) AND (R OR  Q) resolves to (P OR R) –Resolvent: A new statement deduced by resolution –Clause form: A statement whose elementary components are connected by the Boolean operation OR Unification: Assigning a value to a variable so that two statements become “compatible.” Declarative Programming 6-45

Copyright © 2015 Pearson Education, Inc. Figure 6.24 Resolving the statements (P OR Q) and (R OR ¬Q) to produce (P OR R) 6-46

Copyright © 2015 Pearson Education, Inc. Figure 6.25 Resolving the statements (P OR Q), (R OR ¬Q), ¬R, and ¬P 6-47

Copyright © 2015 Pearson Education, Inc. Fact: A Prolog statement establishing a fact –Consists of a single predicate –Form: predicateName(arguments). Example: parent(bill, mary). Rule: A Prolog statement establishing a general rule –Form: conclusion :- premise. :- means “if” –Example: wise(X) :- old(X). –Example: faster(X,Z) :- faster(X,Y), faster(Y,Z). Prolog 6-48

Copyright © 2015 Pearson Education, Inc. EndofChapter