Tải bản đầy đủ (.pdf) (62 trang)

Nguyên lý các ngôn ngữ lập trình

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.05 MB, 62 trang )

IT6020
(c) PGS.TS. H.Q.Thắng, Dep. of SE
1
IT6020 Nguyên l cc ngôn ng
lp trnh
Lecturer: Dr. Huỳnh Quyết Thắng,
Assoc. Prof at Dept. of Software Engineering,
SoICT, HUST
Email:
Mobile: 0913536752
Chương 1 – Tng quan v ngôn ng
lp trnh v chương trnh dch
2
Content of Lesson
1. Object-oriented programming
2. Compilation, Syntax and Semantic of
Programming Language
3. Introduction to Programming Concepts
(c) PGS.TS. H.Q.Thắng, Dep. of SE
IT6020
3
1. Overview
What’s Programming Language (PL)
Principles of Programming language
Programming Paradigms and application
domains
Pragmatic considerations
A brief history of programming language
Programming language quality
(c) PGS.TS. H.Q.Thắng, Dep. of SE
IT6020


4
1.1. What’s Programming Language
What is a programming language?
 Abstraction of virtual machine
int sum(int[] x) {
int sum = 0;
n = 0;
while (n < x.length) {
sum += x[n];
}
return sum;
}
00101010101010
10101011111010
11101010101110
00101010101010

(c) PGS.TS. H.Q.Thắng, Dep. of SE
IT6020
5
1.1. What’s Programming Language
What is a programming language?
 Donald Knuth (The Art of Computer
Programming):
 Programming is the art of telling another human
being what one wants the computer to do
int sum(int[] x) {
int sum = 0;
n = 0;
while (n < x.length) {

sum += x[n];
}
return sum;
}
00101010101010
10101011111010
11101010101110
00101010101010

(c) PGS.TS. H.Q.Thắng, Dep. of SE
IT6020
(c) PGS.TS. H.Q.Thắng, Dep. of SE
6
1.2. Overview-Principle of Programming Language
Syntax: Basic vocabulary of words and symbols
 Grammar for writing programs in the Language: linguistic
formalism (context-free grammar)
Type systems and semantics: Types of values that
programs can manipulate and the meaning (semantics) of
these programs.
Memory management: Collection of techniques that help
us to understand the mechanism of mapping value, data
structures, static and dynamic memory. stack and the heap
lifetime of variables, object
Exception handling: Fundamental techniques of
programming language, Kind of events occur unexpectedly
during the run of a program
IT6020
AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE
7

1.3. Ovier-View Programming Paradigms and
application domains
Major programming paradigm:
 Imperative programming
 Object-Oriented Programming
 Functional Programming
 Logic Programming
 Event-Driven Programming
 Concurrent Programming
Application Domain
 Scientific computing
 Management information system
 Artificial intelligence
 System
 Web-Centrics
AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE
8
1.4. Overview-Pragmatic considerations
Considerations for programming language
 Architecture constrains
 Contextual constrains
 Virtual machines and interpreters
 Standard
 Legacy systems
AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE
9
1.4. Overview-Pragmatic considerations
Architecture constrains: programming language are
designed for computer.
Most computer designs over the past several decades

have followed the von-Newman model. Many
programming languages are well-matched with this
architecture.
CISC, RISC: Lisp machine
AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE
10
1.4. Overview-Pragmatic considerations
Contextual Constraints: programming languages are
designed to satisfy other constrains imposed by the
context in which they are used: the application area,
the operating system, the network, and preference of
the programming community.
AT in PMT
11
Levels of Language in Computing
Figure 1.1
(c) PGS.TS. H.Q.Thắng, Dep. of SE
AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE
12
1.4. Overview-Pragmatic considerations
Virtual Machines and Interpreters: Some time a
language is designed so that the compiler is written
only one using a virtual machine as the target
machine and then that virtual machine is
implemented by an interpreter on each of the
different real machines of the days.
 General interpreter model is shown in figure 1.2.
AT in PMT
13
Virtual Machines and Interpreters Used in this Text

Figure 1.2
(c) PGS.TS. H.Q.Thắng, Dep. of SE
AT in PMT
14
1.4. Overview-Pragmatic considerations
Standard: When a programming language receives
wide enough attention and use among programmers,
the process of standardization usually begins.
 Two major organizations that oversee and maintain
standard for programming languages
 American National Standards Institute (ANSI)
 International Standard Organization (ISO)
 Information about language standard: WWW.ANSI.ORG
(c) PGS.TS. H.Q.Thắng, Dep. of SE
AT in PMT
15
1.4. Overview-Pragmatic considerations
Legacy System: Is has been estimated 90 percent of a
programmer’s time is spent maintaining existing
applications or legacy system, that were designed
and implemented by others and 10 percent is spent
developing code for new applications.
A Brief Historical Lineage of Some Key Programming
Languages is shown in Figure 1.3
(c) PGS.TS. H.Q.Thắng, Dep. of SE
AT in PMT
(c) PGS.TS. H.Q.Thắng, Dep. of SE
16
AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE
17

Content of Lesson
1. Overview of programming language
2. Compilation, Syntax and Semantic of
Programming Language
3. Introduction to Programming Concepts
4. Imperative programming model and
techniques:
4.1. Imperative Programming Model
4.2. Memory Management
4.3. Some Typical Programming Techniques
4.4. Some exercises
AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE
18
2. Syntax and Semantics of Programming
Language
Compiling and Compiling process
Syntax (grammar)
 Formal methods and language processing
 Syntactic analysis
 Linking syntax and semantics
Semantics (meaning)
AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE
19
2.1. Compilation and Interpretation
A compiler is a program that translates high-level source
programs into target program
An interpreter is a program that executes another program
AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE
20
Mixing Compilation and Interpretation

Fuzzy difference:
 A language is interpreted when the initial translation is
simple
 A language is compiled when the translation process is
complicated
AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE
21
Preprocessing
Macros
 #define <macro> <replacement name>
 #define FALSE 0
 #define max(A,B) ( (A) > (B) ?
(A):(B))
AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE
22
Linking
Libraries of subroutines
AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE
23
Portability
Assembly language instead of machine language
Intermediate source code
AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE
24
Programming Environments
Much more than compilers and interpreters
 Assemblers, debuggers, preprocessors and linkers
 Editors
 Pretty printers
 Style Checkers

 Version management
 Profilers
Integrated environments
 Beyond a simple bus error
 Emacs
AT in PMT (c) PGS.TS. H.Q.Thắng, Dep. of SE
25
Overview of Compilation
program gcd(input, output);
var i, j: integer;
begin
read(i, j);
while i <> j do
if i > j then i := i – j;
else j := j – i;
writeln(i)
end.
Compilation

×