Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— 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 FA and PDA Schematics State control a a b b State control a a b b xyzxyz FA PDA Stack: Infinite LIFO (last in first out) device

5 Formal Definition of PDA A pushdown automaton is a 6-tuple (Q, Σ, , , q 0, 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  q 0 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 0 & push 0 on stack read ε & push ε on stack read ε & push $ on stack read 1 & pop 0 off stack read ε & pop $ off stack Language accepted: {0 n 1 n | n  0}

8 Example Read (()()) q start q accept ε, ε  S$ ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () S$S$ q loop

9 Example Read (()()) q start q accept ε, ε  S$ ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop (S)$(S)$

10 Example Read (()()) q start q accept ε, ε  S$ ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop S)$S)$ (

11 Example Read (()()) q start q accept ε, ε  S$ ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop S SS)$SS)$ (

12 Example Read (()()) q start q accept ε, ε  S$ ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop ()S)$()S)$ (

13 Example Read (()()) q start q accept ε, ε  S$ ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop )S)$)S)$ ((

14 Example Read (()()) q start q accept ε, ε  S$ ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop S)$S)$ (()

15 Example Read (()()) q start q accept ε, ε  S$ ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop ())$())$ (()

16 Example Read (()()) q start q accept ε, ε  S$ ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop ))$))$ (()(

17 Example Read (()()) q start q accept ε, ε  S$ ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop )$)$ (()()

18 Example Read (()()) q start q accept ε, ε  S$ ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop $ (()())

19 Example Read (()()) q start ε, ε  S$ ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop (()()) q accept

20 More Examples L= {a i b j c k, i=j or j=k>, and i,j,k>=0}. L= {ww R | 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 (0 n 1 n ) example

22 Instantaneous descriptions

23

24 Equivalence of pda and cfg

25 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

26 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

27 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

28 Idea of PDA construction for A  xBz State control a b AtAt State control a b xBztxBzt

29 Given G build PDA

30

31 Deterministic PDA

32

33


Download ppt "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."

Similar presentations


Ads by Google