200 likes | 413 Views
Pushdown Automata (PDA) A PDA P is a 7-tuple (Q, , , , q 0 , Z 0 , F)
E N D
Pushdown Automata (PDA) A PDA P is a 7-tuple (Q, , , , q0, Z0, F) where Q is a finite set of states, is a finite set of input symbols, is a finite set of stack alphabet, (called the transition function) is a mapping from Q{} to subsets of Q*, q0 is the start state, Z0 is the start symbol (initial stack symbol), and F the set of final states.
Example: P= ({q0, q1, q2}, {0,1}, {0,1, Z}, , q0, Z, {q2}) (q0,0,Z) = {(q0, 0Z)}, (q0,1,Z) = {(q0, 1Z)} (q0,0,0) = {(q0, 00)}, (q0,0,1) = {(q0, 01)} (q0,1,0) = {(q0, 10)}, (q0,1,1) = {(q0, 11)} (q0,,Z) = {(q1, Z)}, (q0,,0) = {(q1, 0)}, (q0,,1) = {(q1, 1)}, (q1,,Z) = {(q2, Z)}, (q1,0,0) = {(q1, )}, (q1,1,1) = {(q1, )}
Let P = (Q, , , , q0, Z0, F) be a PDA. A configuration of P is a triple (q, w, ) in Q**, where • q represents the current state of the finite control • w represents the unread portion of the input. The first symbol of w is under the input head. If w = , it is assumed that all of the input has been read. • represents the contents of the stack. The leftmost symbol of is the topmost symbol on the stack. If , then the stack is empty.
A move by P is a binary relation on the configurations (denoted by |– ). (q, aw, Z) |– (q, w, ) if (q, a, Z) contains (q, ) for any q in Q, a in {}, w in *, Z in , and in *. An initial configuration is of the form (q0, w, Z0) for some w in *. (q, w, ) is also called an instantaneous description (ID).
Theorem 6.5: If P is PDA, and (q, x, ) |–* (p, y, ), then for any string w in * and in *, (q, xw, ) |–* (p, yw, ). Proof: Use induction on the number of moves in the sequence of IDs. Theorem 6.6: If P is PDA, and (q, xw, ) |–* (p, yw, ) for any string w in *, then (q, x, ) |–* (p, y, ).
Let P = (Q, , , , q0, Z0, F) be a PDA. Then the language accepted by P final state L(P) is {w | (q0, w, Z0) |–* (q, , ) for some q in F and in *}. Then the language accepted by P by empty stackN(P) is {w | (q0, w, Z0) |–* (q, , ) for some q in Q }.
Example: Let P = ({q0, q1, q2}, {0, 1}, {0, Z}, , q0, Z, {q0}), where (q0, 0, Z) = {(q1, 0Z)} (q0, 0, 0) = {(q1, 00)} (q1, 1, 0) = {(q2, )} (q2, 1, 0) = {(q2, )} (q2, , Z) = {(q0, )} Show that L(P) = {0n1n | n 0} What is N(P)?
It can be shown that: • (q0, 0, Z) |– (q1, , 0Z) • (q1, 0i, 0Z) |–i (q1, , 0i+1Z) • (q1, 1i, 0iZ) |–i (q2, , Z) • (q2, , Z) |– (q0, , ) 1-4 imply that (q0, 0n1n, Z) |–n+1 (q0, , ) So, {0n1n | n 0} L(P)
If P accepts w , it must cycle through the states q0, q1, q2, q0 If (q0, x, Z) |–i (q1, , ), i 1 then x = 0i and = 0iZ If (q2, y, ) |–i (q2, , ), i 1 then y = 1i and = 0i. If (q1, y, ) |– (q2, , ), then y = 1 and = 0. (q2, x, Z) |– (q0, , ) iff x = So, if (q0, w, Z) |–k (q0, , ), k 0, then k = 0 and w = or k = 2n+1 and w = 0n1n
Theorem 6.9: If L = N(PN) for some PDA PN = (Q, , , N, q0, Z0, F), then there is PDA PF such that L = L(PF). Theorem 6.11: If L = L(PF) for some PDA PF = (Q, , , F, q0, Z0, F), then there is PDA PN such that L = N(PN).
(Theorem 6.9) Construction Let PN = (Q, , , N, q0, Z0, ), then construct PF = (Q {p0, pf}, , {X0}, F, p0, X0, {pf}), where all transitions of PN are included in PF along with the following: • F(p0, , X0) ={(q0, Z0X0)} • F(q, , X0) contains (pf, ) for all q in Q
(Theorem 6.11) Construction Let PF = (Q, , , F, q0, Z0, F), then construct PN = ( Q {p0, p}, , {X0}, N, p0, X0, ), where • N(p0, , X0) ={(q0, Z0X0)} • For q in Q, a in {}, and Y in , N(q,a,Y) contains F(q,a,Y) • For all accepting states q in F and all stack symbols Y in {X0}, N(q, , Y) contains (p, ) • For all stack symbols Y in {X0}, N(p, , Y) = {(p, )}
Theorem 6.13: Let G be a CFG. Then there is a PDA M such that L(G) = N(M). Construction: Let G = (V, T, P, S). Then construct M = ({q}, T, VT, , q, S, ), where is defined as follows: 1. For every A in V, (q, , A) = {(q, ) | A is a production of P. 2. For each terminal a in T, (q, a, a) = {(q,)}
Example: E → E+T | T T → T*F | F E → (E) | a
Theorem 6.14: Let M = (Q, , , , q0, Z0, ) be a PDA, then there is CFG G such that L(G) = N(M). Construction: Let G = (V, , P, S) where V = {S} {[pXq] | p, q are in Q and X in } P consists of productions: 1. S [q0Z0p] for all p in Q 2. Let (q, a, X) contains (r, Y1Y2…Yk), a in {} and k 0. Then for all sequences r1, r2, …,rk of states in Q, [qXrk] a[rY1r1][r1Y2r2]…[rk-1Ykrk] are productions in P.
Example: P = ({p, q}, {0,1}, {X, Z}, , q, Z, ), where (q, 1, Z) = {(q, XZ)} (q, 1, X) = {(q, XX)} (q, 0, X) = {(p, )} (q, , X) = {(q, )} (p, 0, X) = {(p, )} (p, , Z) = {(q, )}
Deterministic Pushdown Automata (DPDA) Definition: A PDA P = (Q, , , , q0, Z0, F) is said to be a deterministic (a DPDA) if for each q in Q and Z in , • (q, a, Z) contains at most one element for each a in and (q, , Z) = or 2) (q, , Z) contains at most one element and (q, a, Z) = for all a in .
Theorem: If L = N(P) for some DPDA P, then L has an unambiguous CFG Theorem: If L = L(P) for some DPDA P, then L has an unambiguous CFG
N(P) has the prefix property • Example 0* not N(P) for DPDA P • If L is a regular language, L is DPDA language • Example: S 0S0 | 1S1 | L(G) is unambiguous, not a DPDA language