1 / 15

PDAs => CFGs

PDAs => CFGs. Sipser 2.2 (pages 119-122). Last time…. Recognizing context-free languages. Lemma 2.21: If a language is context-free, then some pushdown automaton recognizes it. Proof:. Today…. A full characterization.

colum
Download Presentation

PDAs => CFGs

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. PDAs => CFGs Sipser 2.2 (pages 119-122)

  2. Last time…

  3. Recognizing context-free languages • Lemma 2.21: If a language is context-free, then some pushdown automaton recognizes it. • Proof:

  4. Today…

  5. A full characterization • Theorem 2.20: A language is context-free if and only if some pushdown automaton recognizes it. • => by Lemma 2.21 • Now we go backwards!

  6. The proof • Let P = (Q, Σ, Γ, δ, q0, F) be a pushdown automaton. • Assume WLOG (Without Loss Of Generality) • P has exactly one accept state qaccept • P empties its stack before accepting • Each transition does either a push or a pop (but not both)

  7. We build a grammar G… • Given P = (Q, Σ, Γ, δ, q0, F) • Construct G = (V, Σ, R, S), where • V = {Apq | p,q ∈ Q} • Idea: design the rules so that Apq generates all strings that take P from p with empty stack to q with empty stack • S = Aq0, qaccept

  8. Designing the rules

  9. P's operation on strings of Apq • Since P starts and ends with an empty stack: • The first move from p must be a push • The last move to q must be a pop • Along the way, either: • The stack never becomes empty • There is some intermediate state where the stack is empty

  10. Case 1: The stack never empties between p and q • On the first move from p • Letrbe the state moving to • Let a be the input symbol read • Lett be the stack symbol pushed • On the last move to q • Letsbe the state moving from • Letbbe the input symbol read • It must be the case thatt is the stack symbol popped

  11. Capturing this behavior • Model with the rule Apq → aArsb

  12. Case 2: the stack empties along the way from p to q • Let r be the state where the stack is empty • Model with the rule Apq → AprArq

  13. Formally phrasing the rules • If (r, t) ∈ δ(p, a, ε) and (q, ε) ∈ δ(s, b, t) then add the ruleApq → aArsb • For each p, q, r, ∈ Q, add the rule Apq → AprArq • For each p ∈ Q, add the rule App → ε

  14. Proving we were right • Apq generates x if and only if xcan bring P from p with empty stack to q with empty stack • => (Claim 2.30) If Apq generates x, then xcan bring P from p with empty stack to q with empty stack • Proof • By induction on the number of steps in the derivation of x from Apq

  15. And now the other way! • Claim 2.31: If xcan bring P from p with empty stack to q with empty stack, then Apq generates x • Proof • By induction on the number of steps in the computation of P

More Related