ดาวน์โหลดงานนำเสนอ
งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ
ได้พิมพ์โดยสนธิ บราวน์ ได้เปลี่ยน 9 ปีที่แล้ว
1
1 / 51 Introduction to Programming Languages and Evolution of the Major Programming Languages 886340 Principles of Programming Languages 1
2
2 / 51 To gain an understanding of the basic structure of programming languages: - Data types, control structures, naming conventions,... To learn the principles underlying all programming languages: - So that it is easier to learn new languages To study different language paradigms: - Functional (Scheme) - Imperative (C) - Object-Oriented (C++, Java) - Logic (Prolog) So that you can select an appropriate language for a task Course Goals
3
3 / 51 What is Programming Language?
4
4 / 51 “a programming language is a notation for communication to a computer what we want to do” Before the middle of the 1940s, computer operators “hardwired” their programs. In the late 1940s, John von Neumann had the idea. Data and programs stored in memory Memory is separate from CPU Instructions and data are piped from memory to CPU Definition of Programming Language I
5
5 / 51 The von Neumann Architecture
6
6 / 51 Fetch-execute-cycle (on a von Neumann architecture computer) initialize the program counter repeat forever fetch the instruction pointed by the counter increment the counter decode the instruction execute the instruction end repeat The von Neumann Architecture
7
7 / 51 At this point, computer operators became the first true programmers. developed software the machine code to solve problems with computers Machine Language and the First Stored Programs
8
8 / 51 In this program, each line of code contains 16 bits. A line of 16 bits represents either a single machine language instruction or a single data value. Program execution begins with the first line of code, which is fetched from memory, decoded (interpreted), and executed. Machine Language For example, A machine language program
9
9 / 51 mnemonic symbols for the instruction codes and memory locations A program called an assembler translates the symbolic assembly language code to binary machine code. Assembly language For example, An LC-3 assembly language program that adds two numbers
10
10 / 51 But…. The programmer must still do the hard work of translating the abstract ideas of a problem domain to the concrete and machine-dependent notation of a program. Computer hardware architecture has its own machine language instruction set, and thus requires its own dialect of assembly language. Low-Level Language Assembly language
11
11 / 51 “A programming language is a notation system for describing computation in machine-readable and human-readable form” Definition of Programming Language II
12
12 / 51 กระบวนการ (process) ใดๆที่ คอมพิวเตอร์สามารถทำได้ การคำนวณทางคณิตศาสตร์ การจัดการกับข้อมูล (data manipulation) การประมวลผลข้อความ (text processing) การจัดเก็บและการค้นข้อมูล (information storage and retrieval) Computation
13
13 / 51 มีโครงสร้างที่เรียบง่าย ภาษาเครื่องที่ผ่านการแปลแล้วต้องมีความ ชัดเจนไม่กำกวม algorithm ที่ใช้แปลต้องมี complexity อยู่ในระดับที่ยอมรับได้ เพื่อให้การแปลมี ประสิทธิภาพ ดังนั้น ภาษาสำหรับเขียนโปรแกรมจึงต้องมี รูปแบบของไวยากรณ์แน่นอน เรียกว่า context free language Machine readability
14
14 / 51 การทำ abstraction หรือการแทน รายละเอียดของการทำงานของคอมพิวเตอร์ ที่ซับซ้อน เพื่อให้ผู้เขียนโปรแกรมเน้นความสนใจไปที่ งานที่ต้องการแก้ปัญา ดังนั้นภาษาสำหรับเขียนโปรแกรมควรมี โครงสร้างและวิธีการทำงานเป็นแบบ เดียวกับภาษาธรรมชาติ (natural language) Human readability
15
15 / 51 Abstractions in Programming Languages
16
16 / 51 Data abstractions การซ่อนรายละเอียดของการจัดเก็บข้อมูล ให้อยู่ในรูปแบบที่ง่ายต่อการใช้งาน เช่น character string, numbers หรือ binary tree เป็นต้น Control abstractions การซ่อนรายละเอียดของการส่งผ่านการ ควบคุม เช่น loops, คำสั่งที่มีเงื่อนไข ในทางปฏิบัติ และการเรียกใช้โปรแกรม ย่อย เป็นต้น Abstractions in Programming Languages
17
17 / 51 Basic abstraction การ abstract การจัดเก็บข้อมูลพื้นฐานใน หน่วยความจำ การ abstract วิธีการดำเนินการทาง คณิตศาสตร์พื้นฐานกับข้อมูล การ abstract ตำแหน่งที่ใช้เก็บข้อมูลใน หน่วยความจำ ตัวแปร คือ ชื่อของตำแหน่งในหน่วยความจำ และชนิดของข้อมูล ที่เกิดขึ้นจากการประกาศ (declaration) เช่น var x : integer; ในภาษา Pascal หรือ intx; ในภาษา C Data abstractions
18
18 / 51 Structure abstraction การ abstract กลุ่มของข้อมูลที่มี ความสัมพันธ์กัน (data structure) type declaration กำหนดชื่อของชนิด ข้อมูล เช่น การกำหนดกลุ่มของข้อมูลที่เป็นเลข จำนวนเต็มเป็น array เช่น a : array [ 1.. 10 ] of integer; ใน ภาษา Pascal หรือ inta[10]; ในภาษา C Data abstractions
19
19 / 51 Structure abstraction กำหนดให้มีข้อมูลชนิด record เช่น Data abstractions type date = record day : 1..31; month : 1..12; year: 2000..2100; end; struct date { intday; intmonth; intyear; }; typedef struct date date; ภาษา Pascal ภาษา C
20
20 / 51 Unit abstractions การแยกโปรแกรมในส่วนที่ใช้สร้างและการ ใช้งานโครงสร้างข้อมูลออกไว้เป็นสัดส่วน Data encapsulation module และ package Data abstractions
21
21 / 51 Basic abstractions การรวมคำสั่งภาษาเครื่องหลายคำสั่ง เข้าเป็นคำสั่ง ในภาษาระดับสูงคำสั่งเดียว เช่น คำสั่งกำหนดค่า (assignment statement) ในภาษา Pascal เช่น x := x + 3; มีความหมายในคำสั่งภาษา Assembly ของ 80x86 ดังต่อไปนี้ เมื่อกำหนดให้ x เป็นตัวแปร ขนาด 16 บิต และมีตำแหน่งในหน่วยความจำเป็น 1000 movdx, 1000 movax, [dx] movbx, 3 addax, bx mov[dx], ax Control abstractions
22
22 / 51 Structured abstractions การซ้อน (nested) คำสั่งหรือกลุ่มของคำสั่งไว้ ภายใต้เงื่อนไขการทดสอบ เช่น คำสั่ง if, switch case, while, for ในภาษา C Control abstractions IF x > 0.0 THEN numSolns := 2; r1 := sqrt(x); r2 := -r1; ELSE numSolns := 0; END; if ( x > 0.0 ) { numSolns = 2; r1 = sqrt(x); r2 = -r1; } else numSolns = 0; ภาษา Modula-2 ภาษา C If x > 0.0 then begin numSolns := 2; r1 := sqrt(x); r2 := -r1; end else numSolns := 0; ภาษา Pascal
23
23 / 51 Structured abstractions การทำโปรแกรมย่อย เรียกว่า procedure หรือ subprogram หรือ subroutine หรือ function การรวมคำสั่งในภาษาหลายคำสั่งเข้าด้วยกัน เป็นเสมือนหนึ่งคำสั่งเดียว มีองค์ประกอบ 2 ประการ procedure declaration procedure activation Control abstractions
24
24 / 51 Structured abstractions ตัวอย่าง เช่น Control abstractions function gcd(u, v : integer) : integer; var t : integer; begin while v > 0 do begin t := v; v := u mod v; u := t; end; gcd := u; end; int gcd ( int u, int v ) { int tmp; while ( v > 0 ) { t = v; v = u % v; u = t; } return u; } ภาษา Pascal ภาษา C
25
25 / 51 Unit abstractions ภาษาโดยทั่วไปจะมีกลไกในการรวม โปรแกรมย่อยที่มีการทำงานคล้ายคลึงกัน เข้าเป็นกลุ่มเพื่อสะดวกต่อการใช้งาน เช่น การ module ในภาษา Modular-2 และ package ในภาษา Ada function ในภาษา C เป็นต้น ในภาษา C, header file เป็นส่วนกำหนด โครงสร้างและชนิดของข้อมูล Control abstractions
26
26 / 51 Computational Paradigms
27
27 / 51 A way of looking at a problem and seeing a program – What kind of parts do you look for? Problem: Print a “large X” of size n. – E.g., size 5 is X X X X X X What is a Paradigm?
28
28 / 51 Imperative Paradigm Functional Paradigm Logic Programming Paradigm Object-Oriented Paradigm Paradigm
29
29 / 51 A program is: A sequence of state-changing actions Manipulate an abstract machine with: – Variables that name memory locations – Arithmetic and logical operations – Reference, evaluate, assign operations – Explicit control flow statements Fits the Von Neumann architecture closely Key operations: Assignment and “Go To” Imperative Paradigm
30
30 / 51 Example: Imperative Paradigm
31
31 / 51 A program is: Composition of operations on data Characteristics (in pure form): – Name values, not memory locations – Value binding through parameter passing – Recursion rather than iteration Key operations: Function Assignment, Function Application, and Function Abstraction– Based on the Lambda Calculus Functional Paradigm
32
32 / 51 Example: Functional Paradigm
33
33 / 51 A program is: Formal logical specification of problem Characteristics (in pure form): – Programs say what properties the solution must have, not how to find it – Solutions are obtained through a specialized form of theorem-proving Key operations: Unification and NonDeterministic Search – Based on First Order Predicate Logic Logic Programming Paradigm
34
34 / 51 Example: Logic Programming Paradigm
35
35 / 51 A program is: Communication between abstract objects Characteristics: – “Objects” collect both the data and the operations – “Objects” provide data abstraction – Can be either imperative or functional (or logical) Key operation: Message Passing or Method Invocation Object-Oriented Paradigm
36
36 / 51 Example: Object-Oriented Paradigm Java
37
37 / 51 Scientific applications Large numbers of floating point computations; use of arrays >> Fortran Business applications Produce reports, use decimal numbers and characters >> COBOL Artificial intelligence Symbols rather than numbers manipulated; use of linked lists >> LISP Systems programming Need efficiency because of continuous use >> C Web Software Eclectic collection of languages: markup (e.g., HTML), scripting (e.g., PHP), general-purpose (e.g., Java) Programming Domains
38
38 / 51 History of Programming Languages Click here http://oreilly.com/pub/a/oreilly/news/languageposter_0504.html
39
39 / 51 Prehistory 300 B.C. Greece, Euclid invented the greatest common divisor algorithm - oldest known algorithm ~1820-1850 England, Charles Babbage invented two mechanical computational devices - difference engine - analytical engine - Countess Ada Augusta of Lovelace, first computer programmer Precursors to modern machines - 1940’s United States, ENIAC developed to calculate trajectories - 1950’s United States, first high-level PLs invented History of Programming Languages
40
40 / 51 Fortran 1954-57, John Backus (IBM on 704) designed for numerical scientific computation fixed format for punched cards implicit typing only counting loops, if test versus zero only numerical data 1957 optimizing Fortran compiler translates into code as efficient as hand-coded History of Programming Languages
41
41 / 51 Algol60 1958-60, designed by international committee for numerical scientific computation [Fortran] block structure with lexical scope free format, reserved words while loops, recursion explicit types BNF developed for formal syntax definition Cobol 1959-60, designed by committee in US, manufacturers and DoD for business data processing Records focus on file handling English-like syntax History of Programming Languages
42
42 / 51 APL 1956-60 Ken Iverson, (IBM on 360, Harvard) designed for array processing functional programming style LISP 1956-62, John McCarthy (MIT on IBM704,Stanford) designed for non-numerical computation uniform notation for program and data recursion as main control structure garbage collection Snobol 1962-66, Farber, Griswold, Polansky (Bell Labs)designed for string processing powerful pattern matching History of Programming Languages
43
43 / 51 PL/I 1963-66, IBM designed for general purpose computing [Fortran, Algol60, Cobol] user controlled exceptions multi-tasking Simula67 1967, Dahl and Nygaard (Norway) designed as a simulation language [Algol60] data abstraction inheritance of properties Algol68 1963-68, designed for general purpose computing [Algol60] orthogonal language design interesting user defined types History of Programming Languages
44
44 / 51 Pascal 1969, N. Wirth(ETH) designed for teaching programming [Algol60] 1 pass compiler call-by-value semantics Prolog 1972, Colmerauer and Kowalski designed for Artificial Intelligence applications theorem proving with unification as basic operation logic programming History of Programming Languages
45
45 / 51 Recent C 1974, D. Ritchie (Bell Labs) designed for systems programming allows access to machine level within high-level PL efficient code generated Clu 1974-77, B. Liskov (MIT) designed for simulation [Simula] supports data abstraction and exceptions precise algebraic language semantics attempt to enable verification of programs History of Programming Languages
46
46 / 51 Smalltalk mid-1970s, Alan Kay (Xerox Parc), considered first real object-oriented PL, [Simula] encapsulation, inheritance easy to prototype applications hides details of underlying machine Scheme mid-1970s, Guy Steele, Gerald Sussman (MIT) Static scoping and first-class functions History of Programming Languages
47
47 / 51 Modula 1977 N. Wirth (ETH), designed language for large software development [Pascal] to control interfaces between sets of procedures or modules real-time programming Ada 1979, US DoD committee designed as general purpose PL explicit parallelism – rendezvous exception handling and generics (packages) History of Programming Languages
48
48 / 51 C++ 1985, Bjorne Stroustrup (Bell Labs) general purpose goal of type-safe object-oriented PL compile-time type checking templates Java ~1995, J. Gosling (SUN) aimed at portability across platform through use of JVM - abstract machine to implement the PL aimed to fix some problems with previous OOPLs¨ multiple inheritance¨ static and dynamic objects ubiquitous exceptions thread objects History of Programming Languages
49
49 / 51 So you can choose the right language for a given problem – If all you have is a hammer, every problem looks like a nail Why learn more than one PL?
50
50 / 51 So you can learn a new language more easily later – As your job changes, you may need to used different languages – As our understanding of programming improves, new languages are created To learn new ways of thinking about problems – Different languages encourage you to think about problems in different ways – “Paradigms” Why learn more than one PL?
51
51 / 51 Conclusion and Question
งานนำเสนอที่คล้ายกัน
© 2025 SlidePlayer.in.th Inc.
All rights reserved.