1 / 19

Pushdown Automata (PDA) A PDA P is a 7-tuple (Q,  ,  ,  , q 0 , Z 0 , F)

Pushdown Automata (PDA) A PDA P is a 7-tuple (Q,  ,  ,  , q 0 , Z 0 , F)

morrison
Download Presentation

Pushdown Automata (PDA) A PDA P is a 7-tuple (Q,  ,  ,  , q 0 , Z 0 , F)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  2. 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,  )}

  3. 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.

  4. 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).

  5. 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, ).

  6. 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 }.

  7. 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)?

  8. 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)

  9. 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

  10. 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).

  11. (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

  12. (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, )}

  13. 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, VT, , 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,)}

  14. Example: E → E+T | T T → T*F | F E → (E) | a

  15. 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.

  16. 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, )}

  17. 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 .

  18. 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

  19. 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

More Related