You are on page 1of 34

Automat và Ngôn ngữ hình thức

Automata and formal language

Dr. Huỳnh Trung Hiếu


Faculty of Information Technology
HoChiMinh City University of Industry
Welcome to ATM&NNHT
 GV: TS. Huỳnh Trung Hiếu
 Khoa CNTT
 Email: hthieu@gmail.com

 Thông tin môn học:


 Số tín chỉ: 3
 Lên lớp: 45 tiết
 Tự học: 90 tiết

 Yêu cầu:
 Dự lớp trên 75%
 Làm bài tập trên lớp và ở nhà
 Thảo luận theo nhóm
 Làm tiểu luận
 Thi giữa học phần
 Thi kết thúc học phần
Formal Languages & Automata
A formal language:
 Is an abstraction of the general characteristics of
programming languages.

 Consists of a set of symbols and some formation


rules by which these symbols can be combined into
sentences.

3
Formal Languages & Automata
An automaton:
 Is a construction that possesses all the
indispensable features of a digital computer.

 Accepts input, produces output, may have some


temporary storage, and can make decisions in
transforming the input into the output.

4
Formal Languages & Automata

Some immediate and important applications.


 Digital design

 Programming languages

 Compilers

5
Tài liệu

 Giáo trình lý thuyết automat và ngôn ngữ hình thức.


Hồ Văn Quân
 An introduction to formal languages and automata.
Peter Linz
 Introduction to automata theory, languages, and
computation.
John Hopcroft & Jeffrey Ullman
Mục tiêu môn học

 Xây dựng mô hình trừu tượng cho máy tính.


 Lý thuyết cung cấp cho chúng ta những khái niệm giúp
ta đi đến những ứng dụng như :
 Thiết kế kỹ thuật số.

 Ngôn ngữ lập trình.

 Trình biên dịch.

 Nhận dạng ngôn ngữ,….


Nội dung môn học
 Phần 1:Giới thiệu khái niệm, dẫn nhập.
 Phần 2: Automat hữu hạn.
 Phần 3: Ngôn ngữ và văn phạm chính quy.
 Phần 4: Các tính chất của ngôn ngữ chính quy
 Phần 5: Ngôn ngữ phi ngữ cảnh
 Phần 6: Đơn giản văn phạm vi ngữ cảnh
 Phần 7: Automat đẩy xống
 Phần 9: Máy Turing
GiỚI THIỆU KHÁI NiỆM, DẪN NHẬP
Three Basic Concepts

 Languages

 Grammars

 Automata

10
Languages
 Là một hệ thống thích hợp nhằm để diễn tả
những ý kiến, sự kiện, khái niệm chắc chắn.
Chúng bao gồm tập hợp các ký hiệu và quy luật

11
Languages
 Alphabet: a finte and nonempty set of symbols
 = {a, b}

 String: finite sequence of symbols from 


w = abaaa

Độ dài chuỗi |w|, chính là số ký tự trong chuỗi.


: empty string
*: the set of all strings on  (+ = *  {})

12
Languages
 Language: a subset L of *

 Word or Sentence: a string in L

13
Languages
 Example 1:
 = {a, b}

* = {, a, b, aa, ab, ba, aaa, ...}

L1 = {a, aa, aab} (finite language)

L2 = {anbn | n  0} = {, ab, aabb, ...}


Các chuỗi aabb, aaaabbbb là các từ trên
ngôn ngữ L2, nhưng chuỗi abb thì không.

14
Languages
 Language concatenation:
L1L2 = {xy | xL1, yL2}

Ln = L L ... L (n times)

L0 = {}

15
Languages
 Example 2:
L = {anbn | n  0}

L2 = {anbnambm | n  0, m  0}

16
Languages
 Star-closure:
L* = L0  L1  L2 ...

 Positive closure:

L+ = L1  L2 ...

17
Grammars
 A grammar for a natural language tells us whether a
particular sentence is well-formed or not.
<sentence>  <noun-phrase><predicate>
<noun-phrase>  <article><noun>
<predicate>  <verb>
<article>  a | the khi đó ta có những câu như: "a boy
runs" và "the dog walks" là có
<noun>  boy | dog "dạng đúng" có nghĩa là được sinh ra
từ văn phạm trên.
<verb>  runs | walks

18
Grammars
 Formal grammar:
G = (V, T, S, P)
V: finite set of variables (tập biến)
T: finite set of terminal symbols (tập ký hiệu kết thúc)
SV: start variable (tập biến bắt đầu)
P: finite set of productions (luật sinh)

19
Grammars
 Productions: Điểm chủ yếu của văn phạm
xy
x(VT)+ y(VT)*
 w = uxv derives (dẫn xuất ra) z = uyv
wz
w1 * wn (w1  w2  ...  wn | w1 = wn)
w1 + wn

kí hiệu * cho biết dẫn xuất đến wn thì qua một số bước (số bước có thể = 0)

20
Grammars
 Generated language:
Cho G = (V, T, S, P) là 1 văn phạm thì tập:
L(G) = {wT* | S * w} là ngôn ngữ được sinh ra
bởi G
 Derivation: nếu wL(G) thì tồn tại dẫn xuất:
S  w1  w2  ...  wn  w

 Sentential forms: S, w1, w2, ..., wn (containing


variables)

21
Grammars
 Example 3:
G = ({S}, {a, b}, S, P)
P: S  aSb
S

S  aSb  aaSbb  aabb


aabb: sentence aaSbb: sentential form

22
Grammars
 Example 3:
G = ({S}, {a, b}, S, P)
P: S  aSb
S

L(G) = {anbn | n  0}

23
Grammars
 Example 4:
G1 = ({A, S}, {a, b}, S, P1)
P1: S  aAb | 
A  aAb | 

24
Grammars
 Example 4:
G1 = ({A, S}, {a, b}, S, P1)
P1: S  aAb | 
A  aAb | 

L(G1) = {anbn | n  0}

G and G1 are equivalent

25
Grammars
 Để chỉ ra một ngôn ngữ L được sinh ra bởi một văn
phạm G. Chúng ta cần chỉ ra:
a) mỗi w  L được dẫn ra từ S bằng các luật sinh của

văn phạm G.
b) mỗi w như ở (a) phải thuộc L.
Grammars

Tìm văn phạm mà nó sinh ra ngôn ngữ

L = { an bn+1 : n  0 }

Có thể áp dụng ý tưởng của ví dụ 3, và chúng


ta cần làm là sinh ra thêm một kí tự b với luật
sinh:
S --> A b

G = ({S, A}, {a, b}, S, P)


P: S  Ab
A  aAb
A
Grammars
 Example 5:
G2 = ({S}, {a, b}, S, P2)
P2: S  SS
S
S  aSb
S  bSa
=>L(G2) = {w | na(w) = nb(w)}

28
Automata

An abstract model of digital computer:


Input file

Control unit Storage

Output

29
Automata

Input file: is divided into squares.

 Input is a string over a given alphabet.

 Each input square holds a symbol.

 The symbols are read from left to right, one at a time.

 The end of the input string can be detected.

30
Automata

Storage: consists of an unlimited number of cells.

 Each cell can hold a symbol from an alphabet


(which can be different from the input alphabet).

 The contents of the storage cells can be read and


changed.

31
Automata

Control unit: has a finite number of internal states.

 Can be in any one of the internal states.

 Can change state in some defined manner.

32
Automata

 Transition function:
current state  input symbol  storage info  next state

Output may be produced


Info in the storage may be changed

 Configuration: current state  input symbol  storage info

 Move: current configuration  next configuration

33
Automata

 Có các dạng:
 Automat tất định

 Xác định cấu hình hiện tại duy nhất

 Automat không tất định

 Tại mỗi thời điểm có nhiều sự duy chuyển

hơn.
 Accepter: yes/no output
Transducer: string of symbols as output

You might also like