Professional Documents
Culture Documents
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.
3
Formal Languages & Automata
An automaton:
Is a construction that possesses all the
indispensable features of a digital computer.
4
Formal Languages & Automata
Programming languages
Compilers
5
Tài liệu
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}
12
Languages
Language: a subset L of *
13
Languages
Example 1:
= {a, b}
14
Languages
Language concatenation:
L1L2 = {xy | xL1, yL2}
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)
SV: 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
xy
x(VT)+ y(VT)*
w = uxv derives (dẫn xuất ra) z = uyv
wz
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) = {wT* | S * w} là ngôn ngữ được sinh ra
bởi G
Derivation: nếu wL(G) thì tồn tại dẫn xuất:
S w1 w2 ... wn w
21
Grammars
Example 3:
G = ({S}, {a, b}, S, P)
P: S aSb
S
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}
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
L = { an bn+1 : n 0 }
28
Automata
Output
29
Automata
30
Automata
31
Automata
32
Automata
Transition function:
current state input symbol storage info next state
33
Automata
Có các dạng:
Automat tất định
hơn.
Accepter: yes/no output
Transducer: string of symbols as output