Download presentation
Presentation is loading. Please wait.
Published byFrederica Marilyn Sparks Modified over 9 years ago
1
1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages.
2
2 Pushdown Automata {a, b}* is regular. {a k b k | k is a constant} is regular. {a n b n | n 0} is not regular.
3
3 Finite Automata Control unit q 0 Input file yes/no
4
4 Pushdown Automata Control unit q 0 Input file yes/no Stack
5
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
6 Non-deterministic Pushdown Automata (NPDA) : Q ( { }) finite subsets of Q * stack topstack top replacement
7
7 Example (q 1, a, b) = {(q 2, cd), (q 3, )} b d c q1q1 q2q2 q3q3
8
8 Example 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
9 Instantaneous Description (q, w, u) current stateunread part ofstack contents input string
10
10 Instantaneous Description move: (q 1, aw, bx) (q 2, w, yx) iff (q 2, y) (q 1, a, b)
11
11 Instantaneous Description (q 1, x, y) (q 2, u, v) (q 1, x, y) (q 2, u, v)
12
12 Language accepted by NPDA Let M = (Q, , , , q 0, z, F) be an NPDA. L(M) = {w * | (q 0, w, z) (q f,, u), q f F, u * }
13
13 Example L = { w {a, b} * | n a (w) = n b (w) } M = (Q, , , , q 0, z, F) ?
14
14 Example L = { w {a, b} * | n a (w) = n b (w) } M = (Q, , , , q 0, z, F) Q = {q 0, q f } (q 0,, z) = {(q f, z)} = {a, b} (q 0, a, z) = {(q 0, 0z)} = {0, 1, z} (q 0, b, z) = {(q 0, 1z)} F = {q f } (q 0, a, 0) = {(q 0, 00)} (q 0, b, 0) = {(q 0, )} (q 0, a, 1) = {(q 0, )} (q 0, b, 1) = {(q 0, 11)}
15
15 Example L = { ww R | w {a, b} + } M = (Q, , , , q 0, z, F) ?
16
16 Example L = { ww R | w {a, b} + } M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2 } = {a, b} = {a, b, z} F = {q 2 } (q 0, a, a) = {(q 0, aa)} (q 0,, a) = {(q 1, a)} (q 0, b, a) = {(q 0, ba)} (q 0,, b) = {(q 1, b)} (q 0, a, b) = {(q 0, ab)} (q 0, b, b) = {(q 0, bb)} (q 1, a, a) = {(q 1, )} (q 0, a, z) = {(q 0, az)} (q 1, b, b) = {(q 1, )} (q 0, b, z) = {(q 0, bz)} (q 1,, z) = {(q 2, z)}
17
17 NPDA and Context-Free Languages Greibach NF (q 0,, z) = {(q 1, Sz)} S aSA | a (q 1, a, S) = {(q 1, SA), (q 0, )} A bB (q 1, b, A) = {(q 1, B)} B b (q 1, b, B) = {(q 1, )} (q 1,, z) = {(q 2, )}
18
18 Theorem For any context-free language L not containing, there exists an NPDA M such that L = L(M).
19
19 Theorem Proof: G = (V, T, S, P) M = ({q 0, q 1, q f }, T, V {z}, , q 0, z, {q f })z V (q 0,, z) = {(q 1, Sz)} (q 1, u) (q 1, a, A) iff A au P (q 1,, z) = {(q f, z)}
20
20 Example Greibach NF (q 0,, z) = {(q 1, Sz)} S aA (q 1, a, S) = {(q 1, A)} A aABC | bB | a (q 1, a, A) = {(q 1, ABC), (q 1, )} (q 1, b, A) = {(q 1, B)} B b (q 1, b, B) = {(q 1, )} C c (q 1, c, C) = {(q 1, )} (q 1,, z) = {(q 2, )}
21
21 Context-Free Grammars for NPDA M = (Q, , , , q 0, z, F) G = (V, T, S, P) L(G) = L(M)
22
22 Context-Free Grammars for NPDA M = (Q, , , , q 0, z, F) M^: Single final state Final state entered iff the stack is empty (q i, a, A) = {c 1, c 2,..., c n } c i = (q j, ) c i = (q j, BC)
23
23 Context-Free Grammars for NPDA (q i, a, A) = {(q j, ),... } ?
24
24 Context-Free Grammars for NPDA (q i, a, A) = {(q j, ),... } ? At q i erase A and move to q j if receiving a
25
25 Context-Free Grammars for NPDA (q i, a, A) = {(q j, BC),... } ?
26
26 Context-Free Grammars for NPDA (q i, a, A) = {(q j, BC),... } ? At q i erase A and move to q k if receiving a and at q j erase BC and move to q k
27
27 Context-Free Grammars for NPDA (q i, a, A) = {(q j, BC),... } ? At q i erase A and move to q k if receiving a and at q j erase BC and move to q k At q i erase A and move to q k if receiving a and at q j erase B and move to q m and at q m erase C and move to q k
28
28 Context-Free Grammars for NPDA (q i, a, A) = {(q j, ),... } At q i erase A and move to q j if receiving a (q i Aq j ) a
29
29 Context-Free Grammars for NPDA (q i, a, A) = {(q j, BC),... } At q i erase A and move to q k if receiving a and at q j erase B and move to q m and at q m erase C and move to q k (q i Aq k ) a(q j Bq m )(q m Cq k )
30
30 Context-Free Grammars for NPDA Start symbol: (q 0 zq f )
31
31 Example M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2 } = {a} = {A, z} F = {q 2 } (q 0, a, z) = {(q 0, Az)} (q 0, a, A) = {(q 0, A)} (q 0, b, A) = {(q 1, )} (q 1,, z) = {(q 2, )}
32
32 Example M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2, q 3 } = {a} = {A, z} F = {q 2 } (q 0, a, z) = {(q 0, Az)} (q 0, a, A) = {(q 0, A)} (q 0, a, A) = {(q 3, )} (q 0, b, A) = {(q 1, )} (q 3,, z) = {(q 3, Az)} (q 1,, z) = {(q 2, )} (q 0, b, A) = {(q 1, )} (q 1,, z) = {(q 2, )}
33
33 Example M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2, q 3 } = {a} = {A, z} F = {q 2 } (q 0, a, z) = {(q 0, Az)} (q 0, a, A) = {(q 3, )} (q 0 Aq 3 ) a (q 3,, z) = {(q 3, Az)} (q 0, b, A) = {(q 1, )} (q 0 Aq 1 ) b (q 1,, z) = {(q 2, )} (q 1 zq 2 )
34
34 Example M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2, q 3 } = {a} = {A, z} F = {q 2 } (q 0, a, z) = {(q 0, Az)} (q 0 zq 0 ) ... (q 0, a, A) = {(q 3, )} (q 0 zq 1 ) ... (q 3,, z) = {(q 3, Az)} (q 0 zq 2 ) ... (q 0, b, A) = {(q 1, )} (q 0 zq 3 ) ... (q 1,, z) = {(q 2, )}
35
35 Example M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2, q 3 } = {a} = {A, z} F = {q 2 } (q 0, a, z) = {(q 0, Az)} (q 0 zq 0 ) a(q 0 Aq 0 )(q 0 zq 0 ) | (q 0, a, A) = {(q 3, )} a(q 0 Aq 1 )(q 1 zq 0 ) | (q 3,, z) = {(q 3, Az)} a(q 0 Aq 2 )(q 2 zq 0 ) (q 0, b, A) = {(q 1, )} a(q 0 Aq 3 )(q 3 zq 0 ) (q 1,, z) = {(q 2, )}...
36
36 Theorem If L = L(M) for some NPDA M, then L is a context-free language.
37
37 Theorem Proof: M = (Q, , , , q 0, z, {q f }) G = (V, T, S, P) T = V = {(q i Aq j ) | A }S = (q 0 zq f ) P: (q i Aq j ) a iff (q j, ) (q i, a, A) (q i Aq m ) a(q i Bq m )(q m Cq j ) iff (q j, BC) (q i, a, A)
38
38 Deterministic 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 .
39
39 Deterministic Context-Free Language A language L is said to be a DCFL iff there exists a DPDA M such that L = L(M).
40
40 Example M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2 } (q 0, a, 0) = {(q 1, 10)} = {a, b} (q 1, a, 1) = {(q 1, 11)} = {0, 1} (q 1, b, 1) = {(q 2, )} z = 0 (q 2, b, 1) = {(q 2, )} F = {q 0 } (q 2,, 0) = {(q 0, )} L = {a n b n | n 0}
41
41 Homework Exercises: 5, 10, 13 of Section 7.1 - Linz’s book. Exercises: 1, 2, 4, 5, 8, 12 of Section 7.2 - Linz’s book. Exercises: 1, 2, 3, 6, 7 of Section 7.2 - Linz’s book. Presentations: Section 6.3 and Section 7.4.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.