Chapter 7: Pushdown AutomataQuan Thanh Tho qttho@cse.hcmut.edu.vn... Pushdown Automata• There are context-free languages that are not regular.. • Finite automata cannot recognize all con
Trang 1Chapter 7: Pushdown Automata
Quan Thanh Tho qttho@cse.hcmut.edu.vn
Trang 2Pushdown Automata
• There are context-free languages that are not regular.
• Finite automata cannot recognize all context-free languages.
Trang 3Example 7.1
• {a, b}* is regular.
• {akbk | k is a constant} is regular.
• {anbn | n ≥ 0} is not regular.
Trang 5Non-deterministic Pushdown
Automata (NPDA)
M = (Q, ∑ , Γ , δ , q0, 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
q0 ∈ Q: initial state
z ∈ Γ: stack start symbol
F ⊆ Q: set of final states
Trang 6Transition Function
δ : Q × ( ∑∪ { λ }) × Γ → finite subsets of Q × Γ *
replacement
Trang 7Example 7.2
δ (q1, a, b) = {(q2, cd), (q3, λ )}
b
d c
q
q 2
q
Trang 9Instantaneous Description
(q, w, u)
input string
Trang 10Instantaneous Description Move
move: (q1, a w, b x) | (q2, w, y x)
iff (q2, y) ∈ δ (q1, a, b)
Trang 11Instantaneous Description Transition
(q1, x, y) |∗Μ (q2, u, v) (q1, x, y) |+Μ (q2, u, v)
Trang 12Language accepted by NPDA
Let M = (Q, ∑ , Γ , δ , q0, z, F) be an NPDA.
L(M) = {w ∈ Σ * | (q0, w, z) |∗Μ (qf, λ , u), qf ∈ F, u ∈ Γ *}
Trang 15NPDA and Context-Free Languages
Trang 16Theorem 7.1
For any context-free language L not containing λ , there exists
an NPDA M such that L = L(M).
Trang 19Context-Free Grammars for NPDA
M = (Q, ∑ , Γ , δ , q0, z, F)
G = (V, T, S, P) L(G) = L(M)
Trang 20Context-Free Grammars for NPDA
M = (Q, ∑ , Γ , δ , q0, z, F)
M^: Single final state
Final state entered iff the stack is empty
δ (qi, a, A) = {c1, c2, , cn}
ci = (qj, λ ) ci = (qj, BC)
Trang 21Context-Free Grammars for NPDA
δ (qi, a, A) = {(qj, λ ), }
At qi erase A and move to qj if receiving a
(qiAqj) → a
Trang 22Context-Free Grammars for NPDA
δ (qi, a, A) = {(qj, BC), } ?
At qi erase A and move to qk if receiving a and
at qj erase BC and move to qk
At qi erase A and move to qk if receiving a and
at qj erase B and move to qm and
at qm erase C and move to qk
Trang 23Context-Free Grammars for NPDA
δ (qi, a, A) = {(qj, BC), }
At qi erase A and move to qk if receiving a and
at qj erase B and move to qm and
at qm erase C and move to qk
Trang 24Context-Free Grammars for NPDA
Start symbol: (q0zqf)
Trang 30Theorem 7.2
If L = L(M) for some NPDA M, then L is a context-free
language.
Trang 32Deterministic Pushdown Automata
A DPDA is a pushdown automaton that never has a
choice in its move:
1 δ (q, a, b) contains at most one element.
2 if δ (q, λ , b) is not empty, then δ (q, a, b) must be empty for
every a ∈ Σ
Trang 33Deterministic Context-Free
Language
A language L is said to be a DCFL iff there exists a
DPDA M such that L = L(M).
Trang 35• Exercises: 5, 10, 13 of Section 7.1 - Linz’s book.
• Exercises: 1, 2, 3, 4, 5, 6, 7, 8, 12 of Section 7.2 - Linz’s book.