Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 35 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
35
Dung lượng
143 KB
Nội dung
Chapter 7: Pushdown Automata Quan Thanh Tho qttho@cse.hcmut.edu.vn 2 Pushdown Automata • There are context-free languages that are not regular. • Finite automata cannot recognize all context-free languages. 3 Example 7.1 • {a, b}* is regular. • {akbk | k is a constant} is regular. • {anbn | n ≥ 0} is not regular. 4 Pushdown Automata Control unit q 0 Input file yes/no Stack 5 Non-deterministic Pushdown Automata (NPDA) M = (Q, ∑, Γ, δ, q 0 , z, F) Q: finite set of internal states ∑: finite set of symbols - input alphabet Γ: finite set of symbols - stack alphabet δ: Q × (∑∪{λ}) × Γ → finite subsets of Q × Γ* transition function q 0 ∈ Q: initial state z ∈ Γ: stack start symbol F ⊆ Q: set of final states 6 Transition Function δ: Q × (∑∪{λ}) × Γ → finite subsets of Q × Γ* stack top stack top replacement 7 Example 7.2 δ(q 1 , a, b) = {(q 2 , cd), (q 3 , λ)} b d c q 1 q 2 q 3 8 Example 7.3 M = (Q, ∑, Γ, δ, q 0 , z, F) Q = {q 0 , q 1 , q 2 , q 3 } δ(q 0 , a, 0) = {(q 1 , 10), (q 3 , λ)} ∑ = {a, b} δ(q 0 , λ, 0) = {(q 3 , λ)} Γ = {0, 1} δ(q 1 , a, 1) = {(q 1 , 11)} z = 0 δ(q 1 , b, 1) = {(q 2 , λ)} F = {q 3 } δ(q 2 , b, 1) = {(q 2 , λ)} δ(q 2 , λ, 0) = {(q 3 , λ)} 9 Instantaneous Description (q, w, u) current state unread part of stack contents input string 10 Instantaneous Description Move move: (q 1 , aw, bx) | (q 2 , w, yx) iff (q 2 , y) ∈ δ(q 1 , a, b) [...]... erase A and move to q if receiving a i j (q Aq ) → a i j 21 Context-Free Grammars for NPDA δ(q , a, A) = {(q , BC), } i j ? At q erase A and move to q if receiving a and i k at q erase BC and move to q j k At q erase A and move to q if receiving a and i k at q erase B and move to q and j m at q m erase C and move to q k 22 Context-Free Grammars for NPDA δ(q , a, A) = {(q , BC), } i j At q erase A and. .. q erase B and move to q and j m at q m erase C and move to q k 22 Context-Free Grammars for NPDA δ(q , a, A) = {(q , BC), } i j At q erase A and move to q if receiving a and i k at q erase B and move to q and j m at q m erase C and move to q k (q Aq ) → a(q Bq )(q Cq ) i k j m m k 23 Context-Free Grammars for NPDA Start symbol: (q zq ) 0 f 24 Example 7.7 M = (Q, ∑, Γ, δ, q , z, F) 0 Q = {q , q , q... , λ)} 1 1 δ(q , b, z) = {(q , bz)} 0 0 δ(q , λ, z) = {(q , z)} 1 2 14 NPDA and Context-Free Languages Greibach NF δ(q , λ, z) = {(q , Sz)} 0 1 S → aSA | a δ(q , a, S) = {(q , SA), (q , λ)} 1 1 1 A → bB δ(q , b, A) = {(q , B)} 1 1 B→b δ(q , b, B) = {(q , λ)} 1 1 δ(q , λ, z) = {(q , λ)} 1 2 15 Theorem 7.1 For any context-free language L not containing λ, there exists an NPDA M such that L = L(M) 16 Theorem... Theorem 7.2 If L = L(M) for some NPDA M, then L is a context-free language 30 Theorem 7.2 Proof: M = (Q, Σ, Γ, δ, q , z, {q }) 0 f G = (V, T, S, P) T=Σ V = {(q Aq ) | A ∈ Γ} i j S = (q zq ) 0 f P: (q Aq ) → a iff (q , λ) ∈ δ(q , a, A) i j j i (q Aq ) → a(q Bq )(q Cq ) iff (q , BC) ∈ δ(q , a, A) i m i m m j j i 31 Deterministic Pushdown Automata A DPDA is a pushdown automaton that never has a choice in... automaton that never has a choice in its move: 1 2 δ(q, a, b) contains at most one element if δ(q, λ, b) is not empty, then δ(q, a, b) must be empty for every a ∈ Σ 32 Deterministic Context-Free Language A language L is said to be a DCFL iff there exists a DPDA M such that L = L(M) 33 Example 7.8 M = (Q, ∑, Γ, δ, q , z, F) 0 Q = {q , q , q } 0 1 2 δ(q , a, 0) = {(q , 10)} 0 1 ∑ = {a, b} δ(q , a, 1)...Instantaneous Description Transition (q , x, y) |∗ (q , u, v) 1 Μ 2 (q , x, y) |+ (q , u, v) 1 Μ 2 11 Language accepted by NPDA Let M = (Q, ∑, Γ, δ, q , z, F) be an NPDA 0 L(M) = {w ∈ Σ* | (q , w, z) |∗ (q , λ, u), q ∈ F, u ∈ Γ*} 0 Μ f f 12 Example 7.4 L = {w ∈ {a, b}* | n (w) = n (w)} a b M = (Q, ∑, . Pushdown Automata Quan Thanh Tho qttho@cse.hcmut.edu.vn 2 Pushdown Automata • There are context-free languages that are not regular. • Finite automata cannot recognize all context-free languages. 3 Example. is regular. • {anbn | n ≥ 0} is not regular. 4 Pushdown Automata Control unit q 0 Input file yes/no Stack 5 Non-deterministic Pushdown Automata (NPDA) M = (Q, ∑, Γ, δ, q 0 , z, F) Q: finite set. δ(q 1 , b, b) = {(q 1 , λ)} δ(q 0 , b, z) = {(q 0 , bz)} δ(q 1 , λ, z) = {(q 2 , z)} 15 NPDA and Context-Free Languages Greibach NF δ(q 0 , λ, z) = {(q 1 , Sz)} S → aSA | a δ(q 1 , a, S) = {(q 1 ,