Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction Computer science is the discipline that seeks to build a scientific foundation for a variety of topics. Computer science provides the underpinnings.

Similar presentations


Presentation on theme: "Introduction Computer science is the discipline that seeks to build a scientific foundation for a variety of topics. Computer science provides the underpinnings."— Presentation transcript:

1 Introduction Computer science is the discipline that seeks to build a scientific foundation for a variety of topics. Computer science provides the underpinnings for today’s computer applications as well as the foundations for tomorrow’s applications.

2 Ch. 5 Programming Languages Historical perspective. Traditional programming concepts. Program units. Language implementation. Parallel computing. Declarative programming.

3 Historical Perspective Machine language - binary form; directly control the hardware. Assembly language - mnemonic form of the machine language. From machine language to assembly language –still low level –still machine-dependent

4 Historical Perspective Higher level language –machine-independent portability –English-like language Total=Price+Tax –compiler Vs. interpreter

5 Historical Perspective Compiler Assembler 1 Arch 1Arch nAssembler n HLL Machine independent Machine dependent

6 Historical Perspective 1st-generation - machine language. 2nd-generation - assembly language. 3rd-generation - machine independent. 4th-generation - software packages that allow users to customize computer software to their applications without needing technical expertise.

7 Historical Perspective 1st4th Problems solved in an environment in which the human must conform to the machine’s characteristics Problems solved in an environment in which the machine conforms to the human’s characteristics

8 Programming Paradigms Imperative paradigm: based on CPU’s fetch-decode-execute cycle. –development of a sequence of commands which manipulate data to produce the result –procedure paradigm –machine languages, FORTRAN, COBOL, ALGOL, BASIC, APL, C, PASCAL, ADA

9 Programming Paradigms Declarative paradigm implements a general problem-solving algorithm. – GPSS, Prolog –what is the problem? NOT how to solve the problem – 一個親戚關係的問題

10 Programming Paradigms parent(X,Y) :- mother(X,Y) parent(X,Y) :- father(X,Y) sibling(X,Y):- mother(M,X), mother(M,Y), father(F,X), father(F,Y) grandparent(X,Z):- parent(X,Y), parent(Y,Z)

11 Programming Paradigms Functional paradigm –views the process of program development as the construction of “black boxes,” each accepts inputs and produces outputs (Divide (Sum Numbers)(Count Numbers)) (First (Sort List)) –modular approach –LISP, ML, Scheme

12 Programming Paradigms Object-oriented paradigm: units of data are viewed as active “objects” rather than the passive units envisioned by the imperative paradigm. SIMULA, Smalltalk, C++, Ada95, Java. Data methods

13 Programming Paradigms Active object: data and a collection of procedures for manipulating the data. –icons: click and drag –NOT designing an algorithm to manipulate the data, but asking the object to do it itself –passing messages as in computer networks –building block and software reuse CORBA: implementing message passing between objects in a network.

14 Traditional Programming Concepts Statements in programming languages tend to fall into three categories: declarative statements, imperative statements, and comments. Declarative statements - define customized terminology used in the program. Imperative statements - describe steps in the underlying algorithm. Comments.

15 Traditional Programming Concepts Variable, literal, and constant. Data type - integer, real, Boolean, character (Figure 5.4). Data structure - homogeneous array and heterogeneous array (Figures 5.5 and 5.6). Assignment statement. –operator precedence 2 * 4 + 6 / 2

16 Traditional Programming Concepts –overloading: the meaning of a symbol is determined by the data types of the operands “+” can be addition or concatenation Control statement. –rat’s nests by “go to” –Figures 5.7 and 5.8 –only a few of these structures are needed the choice of which to incorporate into a language is a design decision structured programming Comments - internal documentation.

17 Procedural Units Breaking large programs into manageable units. Procedures. –local variable and global variable –parameters in procedure’s header formal parameters and actual parameters pass by value and pass by reference (Figures 5.10 and 5.11) Functions. I/O statements.

18 Language Implementation Translation - converting a program from one language to another. Translation involves three activities (Figure 5.12): –Lexical analysis –Parsing –Code generation Lexical analysis - recognizing which strings of symbols from the source program represent a single entity.

19 Language Implementation Parsing - identifying the grammatical structure of the program and recognizing the role of each component. –The man the horse that lost the race threw was not hurt – Fixed-format languages Vs. free-format languages punctuation marks/key words/reserved words – Syntax rules by diagrams (Figures 5.13 and 5.14)

20 Language Implementation –Parse tree (Figure 5.15) parsing -> constructing parse trees one string -> one parse tree (Figure 5.16) –Parsing declarative statements -> symbol table (data types) –Total = Price + Tax integer addition op-code floating-point addition op-code coercion strongly typed

21 Language Implementation Code generation - constructing the machine language instructions to simulate the statements recognized by the parser. Code optimization. –x = y + z; w = x + z; –x and z need not be loaded from memory for computing w

22 Language Implementation Linker - link all necessary object programs to produce a complete, executable program. –Load module Loader - place the program in memory for execution. –Multitasking –Relocatable module a jump instruction must jump to the correct address within the program Figure 5.18.

23 Object-Oriented Programming class SmallBusiness { … } SmallBusiness BusinessX; class MailOrder Business extends SmallBusiness { … } MailOrderBusiness BusinessY; –Inheritance –Polymorphism Vs. overloading Encapsulation: restrict access to an object’s internal properties

24 Parallel Computing Developing languages for describing processes that execute simultaneously. Process spawning. Interprocess communication Monitor controls access to shared data –Object-oriented paradigm

25 Declarative Programming Logical deduction - resolution. –From P OR Q and R OR -Q, we conclude P OR R –From -P -> Q and Q -> R, we conclude -P -> R Resolution can be applied only to pairs of statements that appear in clause form. Inconsistent collection of statements –P and -P –Repeated application of resolution produces an empty clause (Figure 5.20)

26 Declarative Programming To conform that a collection of statements implies P => to contradict -P => to apply resolution to the original collection of statements and -P to produce an empty clause From (Mary is at X) -> (Mary’s lamb is at X) and Mary is at home, we conclude (Mary’s lamb is at home) –unification

27 Declarative Programming Prolog (PROgramming in LOGic) - a declarative programming language based on repeated resolution. Facts: faster(turtle,snail). faster(rabbit,turtle). Rule: faster(X,Z) :- faster(X,Y), faster(Y,Z). Deduce faster(rabbit,snail). faster(W,snail). faster(rabbit,W). faster(V,W). faster(snail,rabbit).


Download ppt "Introduction Computer science is the discipline that seeks to build a scientific foundation for a variety of topics. Computer science provides the underpinnings."

Similar presentations


Ads by Google