0% found this document useful (0 votes)
73 views8 pages

Nhập môn chương trình dịch

The document provides information about an introductory course on compiler construction. It discusses the instructor, motivation for studying compilers, what will be covered in the course, expectations for what students will achieve, references for further reading, and gives an overview of programming language generations and characteristics of high-level languages. The document aims to provide students background and context for the compiler construction course.

Uploaded by

tutamasdfghjkl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views8 pages

Nhập môn chương trình dịch

The document provides information about an introductory course on compiler construction. It discusses the instructor, motivation for studying compilers, what will be covered in the course, expectations for what students will achieve, references for further reading, and gives an overview of programming language generations and characteristics of high-level languages. The document aims to provide students background and context for the compiler construction course.

Uploaded by

tutamasdfghjkl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

9/10/2016

Nhập môn chương trình dịch

Trịnh Tuấn Đạt


Bộ môn CNPM, Viện CNTT-TT

Thông tin về khóa học


 Giảng viên:
 Trịnh Tuấn Đạt
 Bộ môn CNPM, Viện CNTT-TT
 Email: dattt@soict.hust.edu.vn
 Phone: 016 9299 0092
 Bài giảng:
 http://goo.gl/Tgy9HL

Motivation for doing this course


 Language processing is an important component of programming

 A large number of systems software and application programs


require structured input

 Operating Systems (command line processing)

 Databases (Query language processing)

 Type setting systems like Latex, Nroff, Troff, Equation editors, M4

 VLSI design and testing,

 Software quality assurance and software testing

1
9/10/2016

Motivation for doing this course


 XML, html based systems, Awk, Sed, Emacs, vi ….

 Form processing, extracting information automatically from forms

 Compilers, assemblers and linkers

 High level language to language translators

 Natural language processing

 Where ever input has a structure one can think of language processing

 Why study compilers?


Compilers use the whole spectrum of language processing technology

Many common applications require structured input


during development phase (design of banner
programme of Unix)

xxxxxxxxx 9x
xxxxxxxxx 9x
xxxxxxxxx 9x
xxx 3b 3x
xxx 3 9x
3b 3x
xxx 6 3b 3x
3b 3x
xxx 3 9x
3b 3x
xxx 3b 3x
xxx 3b 3x
xxxxxxxxx 9x
xxxxxxxxx 9x
xxxxxxxxx 9x
5

What will we learn in the course?


 How high level languages are implemented to generate machine code. Complete
structure of compilers and how various parts are composed together to get a
compiler

 Course has theoretical and practical components. Both are needed in


implementing programming languages. The focus will be on practical application
of the theory.

 Emphasis will be on algorithms and data structures rather than proofs of


correctness of algorithms.

 Theory of lexical analysis, parsing, type checking, runtime system, code


generation, optimization (without going too deep into the proofs etc.)

 Techniques for developing lexical analyzers, parsers, type checkers, run time
systems, code generator, optimization. Use of tools and specifications for
developing various parts of compilers

2
9/10/2016

What do we expect to achieve by the end of the


course?

 Students are confident that they can use


language processing technology for various
software developments

 Students are confident that they can design,


develop, understand, modify/enhance, and
maintain compilers for (even complex!)
programming languages

References
 Compilers: Principles, Tools and Techniques by Aho, Sethi and Ullman
soon to be replaced by “21st Century Compilers” by Aho, Sethi, Ullman, and Lam

 Crafting a Compiler in C by Fischer and LeBlanc


soon to be replaced by “Crafting a Compiler” by Fischer

 Compiler Design in C by Holub

 Programming Language Pragmatics by Scott

 Engineering a Compiler by Cooper and Torczon

 Modern Compiler Implementation (in C and in Java) by Appel

 Writing Compilers and Interpreters by Mak

References
 Compiler Design by Wilhelm and Maurer

 A Retargetable Compiler: Design and Implementation by Fraser and Hanson

 Compiler Construction by Wirth

 The Theory of Parsing, Translation and Compiling (vol 1 & 2) by Aho and Ullman (old classic)

 Introduction to Compiler Construction with Unix by Schreiner and Friedman

 Compiler Design and Construction: Tools and Techniques by Pyster

 Engineering a Compiler by Anklam and Cutler

 Object Oriented Compiler Construction by Holmes

 The Compiler Design Handbook edited by Srikant and Shankar

3
9/10/2016

References
 Bài giảng Lý thuyết và Thực hành Chương Trình Dịch.
Lê Anh Cường, khoa Công Nghệ, ĐHQG Hà nội, 2004

 Giáo trình lý thuyết, thực hành môn học Chương trình


dịch. Phạm Hồng Nguyên, Khoa Công Nghệ, ĐHQG
Hà nội, 1998

 Ngôn ngữ hình thức. Nguyễn Văn Ba, ĐHBK Hà nội,


1994

 Thực hành kỹ thuật biên dịch. Nguyễn Văn Ba, ĐHBK


Hà nội, 1993

10

Đánh giá kết quả


 Chia làm 2 phần:
 Lập trình ứng dụng (chia nhóm)
 Lý thuyết
 Điểm giữa kỳ, cuối kỳ

11

Ngôn ngữ lập trình cấp cao


 Các ngôn ngữ lập trình được chia thành 5 thế
hệ.
 Việc phân chia cấp cao hay thấp phụ thuộc
mức độ trừu tượng của ngôn ngữ
 Cấp thấp: gần với máy
 Cấp cao: cho con người, gần với ngôn ngữ tự
nhiên
 Một chương trình viết bằng ngôn ngữ bậc
cao gọi là mã nguồn (source code)

12

4
9/10/2016

Ngôn ngữ lập trình thế hệ thứ nhất và thứ hai

 Thế hệ thứ nhất: ngôn ngữ máy


 Thế hệ thứ hai: Assembly
 Các ngôn ngữ thuộc thế hệ thứ nhất và thứ
hai là ngôn ngữ lập trình cấp thấp

13

Ngôn ngữ lập trình thế hệ thứ ba

 Dễ hiểu hơn
 Cho phép thực hiện các khai báo, chẳng hạn
khai báo biến
 Phần lớn các ngôn ngữ cho phép lập trình
cấu trúc
 Ví dụ: Fortran, Cobol, C, C++, Basic . . .

14

Ngôn ngữ lập trình thế hệ thứ tư

 Thường được sử dụng trong một lĩnh vực cụ


thể (chẳng hạn thương mại)
 Dễ lập trình, xây dựng phần mềm
 Có thể kèm công cụ tạo form, báo cáo
 Ví dụ: SQL, Visual Basic, Oracle (SQL plus,
Oracle Form, Oracle Report), . . .

15

5
9/10/2016

Ngôn ngữ lập trình thế hệ thứ năm

 Giải quyết bài toán dựa trên các ràng buộc đưa
ra cho chương trình chứ không phải giải thuật
của người lập trình.
 Việc giải quyết bài toán do máy tính thực hiện
 Phần lớn các ngôn ngữ dùng để lập trình logic,
giải quyết các bài toán trong lĩnh vực trí tuệ
nhân tạo

16

Đặc trưng của ngôn ngữ lập trình cấp cao

 Độc lập với máy tính


 Gần với ngôn ngữ tự nhiên
 Chương trình dễ đọc, viết và bảo trì
 Muốn thực hiện chương trình phải dịch sang
ngôn ngữ máy
 Chương trình thực hiện chậm hơn

17

Cú pháp và ngữ nghĩa của ngôn ngữ lập trình

 Cú pháp : Chính tả và văn phạm của các cấu


trúc ngôn ngữ
 Ngữ nghĩa: Ý nghĩa và hiệu quả của các cấu
trúc ngôn ngữ

18

6
9/10/2016

Bộ xử lý ngôn ngữ (Language Processor)

 Phần mềm dịch từ một ngôn ngữ nào đó


sang mã máy (có thể đồng thời thực thi)
 Ví dụ
 …ompiler
C
 Assembler

 Interpreter

19

Compiler & Interpreter


 Compiler & interpreter đều là các chương
trình chuyển mã nguồn viết bằng ngôn ngữ
bậc cao sang mã máy - ngôn ngữ mà máy
tính hiểu được.

20

Compiler & Interpreter


 Compiler : Dịch trực tiếp ra mã máy

 Mã nguồnScannerParser…Code generatorMã
máyLoaderExecuter

 Interpreter: Thực hiện trực tiếp từng lệnh mã nguồn

 Mã nguồnScannerParserThông dịch

 Biến thể của Interpreter: thông dịch mã trung gian

 Mã nguồn … Compiler … Mã trung gianVM

21

7
9/10/2016

Compiler vs. Interpreter


Interpreter Compiler
 Mỗi lần dịch từng câu lệnh  Quét và dịch toàn bộ chương
trong chương trình trình sang ngôn ngữ máy
 Tốn ít thời gian hơn để  Tốn nhiều thời gian hơn để
phân tích mã nguồn, nhưng phân tích mã nguồn, nhưng
tổng thể lại tốn nhiều thời tổng thể lại nhanh hơn
gian hơn  Sinh ra code trung gian, sau
đó cần phải liên kết lại với
 Không sinh code trung gian, nhau, nên cần nhiều bộ nhớ
nên sử dụng bộ nhớ hiệu hơn
quả hơn  Sinh ra thông điệp báo lỗi chỉ
 Tiếp tục dịch chương trình khi quét qua toàn bộ chương
cho đến khi gặp lỗi đầu trình. Vì vậy việc debug nói
tiên. Vì vậy debug dễ hơn chung là khó khăn
 VD: Python, Ruby  VD: C, C++

22

Compiler

Source program

Compiler

Input Executable program Output

23

Interpreter

Source program

Input Interpreter Output

24

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy