1 / 33

CS 3240: Languages and Computation

CS 3240: Languages and Computation. Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10 . PLEASE REFER TO THE TEXTBOOK FOR COMPLETE COVERAGE. Project 1. Pushdown Automata. Similar to finite automata, but for CFG’s

meir
Download Presentation

CS 3240: Languages and Computation

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. CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10 . PLEASE REFER TO THE TEXTBOOK FOR COMPLETE COVERAGE

  2. Project 1

  3. Pushdown Automata • Similar to finite automata, but for CFG’s • Finite automata are not adequate for CFG’s because we cannot keep track of what we’ve done • At any point, we only know the current state, not previous states • Need memory • PDA’s are finite automata with a stack

  4. a a b b a a b b x y z FA and PDA Schematics State control FA State control PDA Stack: Infinite LIFO (last in first out) device

  5. Formal Definition of PDA • A pushdown automaton is a 6-tuple (Q, Σ, , , q0, F), where Q, Σ, , and F are all finite sets, and • Q is the set of states • Σ is the set of input alphabet •  is the stack alphabet • :Q×Σ× ,P(Q×) is the transition function • q0 is the start state and • FQ is the set of accept states

  6. How does PDA work? • Start in start state • Read input character, perform state transition and update stack • Clone a machine if multiple transitions are possible • At end of input if any machine accepts and the stack is empty then accept

  7. Example read ε & pop $ off stack read ε & push $ on stack read ε & push ε on stack read 0 & push 0 on stack read 1 & pop 0 off stack Language accepted: {0n1n | n  0}

  8. Example ε,SSS ε,S(S) ε,S() • Read (()()) S $ ε,ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε

  9. Example ( S ) $ ε,SSS ε,S(S) ε,S() • Read (()()) ε,ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε

  10. Example S ) $ ε,SSS ε,S(S) ε,S() • Read (()()) ε,ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (

  11. Example SS ) $ ε,SSS ε,S(S) ε,S() • Read (()()) ε,ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (

  12. Example ( ) S ) $ ε,SSS ε,S(S) ε,S() • Read (()()) ε,ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (

  13. Example ) S ) $ ε,SSS ε,S(S) ε,S() • Read (()()) ε,ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε ((

  14. Example S ) $ ε,SSS ε,S(S) ε,S() • Read (()()) ε,ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (()

  15. ( ) ) $ Example ε,SSS ε,S(S) ε,S() • Read (()()) ε,ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (()

  16. ) ) $ Example ε,SSS ε,S(S) ε,S() • Read (()()) ε,ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (()(

  17. ) $ Example ε,SSS ε,S(S) ε,S() • Read (()()) ε,ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (()()

  18. $ Example ε,SSS ε,S(S) ε,S() • Read (()()) ε,ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (()())

  19. Example ε,SSS ε,S(S) ε,S() • Read (()()) ε,ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (()())

  20. More Examples • L= {aibjck, i=j or j=k>, and i,j,k>=0}. • L= {wwR | w in {0,1}* }

  21. Differences between PDA’s and NFA’s • Transitions read one symbol of the string and push a string onto or pop a symbol off of the stack • Stack alphabet is not necessarily the same as the alphabet for the language • e.g., $ marks bottom of stack in previous (0n1n) example

  22. Instantaneous descriptions

  23. Equivalence of pda and cfg

  24. Equivalence of PDA’s and CFG’s Theorem: A language is context free if and only if some pushdown automaton accepts it by e.s. Proved in two lemmas – one for the “if” direction and one for the “only if” direction We will only do the “only if” step – i.e., show that every context-free language has an associated PDA

  25. CFG’s are recognized by PDA’s Lemma: If a language is context free, then some pushdown automaton accepts it by emp.st. Proof idea: Construct a PDA following CFG rules

  26. Constructing the PDA • You can read any symbol in  when that symbol is at the top of the stack • Transitions of the form a,aε • The rules will be pushed onto the stack – when a variable A is on top of the stack and there is a rule Aw, you pop A and push w • You accept only if the input is exhausted and the stack is empty

  27. State control State control a b a b x B z t A t Idea of PDA construction for AxBz

  28. Given G build PDA

  29. Deterministic PDA

More Related