Pushdown Automata

Pushdown Automata

Pushdown Automata Machines for Context-Free Languages Wednesday, November 11, 2009 Reading: Sipser 2.2; Kozen 23 CS235 Languages and Automata Department of Computer Science Wellesley College Goals • Complete the analogy: regular expression : finite automaton :: context-free grammar : ??? ??? = pushdown automaton • Study/design some nondeterministic pushdown automata (NPDAs). • Discuss the relationship between CFGs and NPDAs. • Discuss nondeterministic vs. deterministic PDAs. Pushdown Automata 27-2 1 Finite Automata Review A finite automaton accepts/rejects input tape strings that can be viewed as a t 1 t2 t3 t4 t5 t6 … read-onlyyp tape of sy mbols read by a tape head that can move only left to left-to-right, Finite-State right, as controlled by a finite-state read-only Control controller. Comes in many flavors (Stoughton): FA = transitions between states are relations involving arbitrary strings. EFA = transitions are relations involving strings of length 1. NFA = transitions are relations involving strings of length 1. DFA = transitions are functions involving strings of length 1. Other authors define such machines in slightly different ways, sometimes with different names. Pushdown Automata 27-3 Pushdown Automata input tape t1 t2 t3 t4 t t6 … A pushdown automaton is a finite 5 automaton + a stack of symbols that left-to-right, can be pushed/popped on each Finite-State read-only transition. The finite-state Control controller can read only the top push/pop, symbol of the stack, which can can only read top affect the transition. sn top S Comes in many flavors (Sipser/Kozen): n-1 … Nondeterministic Pushdown Automata (Sipser’s PDA, Kozen’s NPDA) = Stoug hton’ s EFA + read top of stack and s2 push/pop stack symbols on each transition. s1 bottom Deterministic Pushdown Automata (DPDA) = Stoughton’s DFA + stack operations + end-of-input symbol . Definitions differ slightly from author to author. Pushdown Automata 27-4 2 An NPDA for On1n Example Execution State Input Stack A A 000111 % B 000111 $ %, % → $ read no input and push B 00111 0$ bottom-of-stack marker $ B 0111 00$ B 0, % → 0 read 0 from input and push 0 onto stack B 111 000$ %, % → % transition to 1-reading state C 111 000$ without reading input C 11 00$ C 1, 0 → % read 1 from input C 1 0$ and pop 0 from stack C % $ %, $ → % read no input and pop $ from stack D % % (Note: not necessary to D pop $ since stack needn’t Each row of table is a be empty at end) machine configuration. * Note: Where we use %, % → $, Transitions go from one Sipser uses , → $. configuration to another. Pushdown Automata 27-5 Formally Defining NPDAs Definitions differ among authors. This one is similar to Sipser’s: A Nondeterministic Pushdown Automaton (NPDA)* in a sextuple: (1) A set of states Q (2) An input alphabet (not containing the empty string symbol %) (3) A stack alphabet (4) A start state s Q (5) A set of final states F Q (6) A transition relation T (Q x ( U %) x ( U %)) x (Q x ( U %)) This is similar to Stoughton’s EFA except: • The input alphabet is explicit (rather than implicitly being Sym) •The stack alphabet is new • The transition relation allows pushing/popping a stack symbol (Stoughton’s transition relation T (Q x ( U %) x Q). ) * Sipser calls it a Pushdown Automaton (PDA) Pushdown Automata 27-6 3 Defining Acceptance for NPDAs A configuration is a triple in Q x *x*. Let p,q in Q; t in ( U %); x, y in *; k,k’ in ( U %); and G in *. We define the step relation, , on configurations: (p, ty, kG) (q, y, k’G) iff ( (p, t, k), (q, k’) ) T A NPDA accepts a string x iff (s, x, %) * (p, %, G) (for some stack G; it needn’t be empty) where s is the start state and p the final states F. Example for 0n1n NPDA (A, 000111, %) (B, 000111, $) (B, 00111, 0$) (B, 0111, 00$) (B, 111, 000$) (C, 111, 000$) (C, 11, 00$) (C, 1, 0$) (C, %, $) (D, %, %) Pushdown Automata 27-7 An NPDA for {Om1n | m > n} How do we complete the following NPDA to do the right thing? (Hint: stack needn’t be empty in accepting state.) State Input Stack A A 000011 % %, % → $ B 000011 $ B 00011 0$ B 0, % → 0 B 0011 00$ B 011 000$ %, % → % B 11 0000$ C 1, 0 → % C 11 0000$ C 1 000$ C % 00$ Pushdown Automata 27-8 4 An NPDA for {w | w {0,1}* and #0s = #1s} Create an NPDA for this language. State Input Stack 11000110 % Pushdown Automata 27-9 An NPDA for {0i1j2k | i = j or i = k} Create an NPDA for this language (use nondeterminism!) State Input Stack 0011122 % Pushdown Automata 27-10 5 An NPDA for {wwR | w {0,1}*} Create an NPDA for this language (use nondeterminism!) State Input Stack 100001 % Pushdown Automata 27-11 NPDAs are Equivalent to CFGs It can be shown that: (()1) A CFG can be converted to an NPDA. Context-Free I.e., every context-free language Languages (CFLs) (the language of some CFG) is the language accepted by some NPDA. CFGs NPDAs (2) An NPDA can be converted to a CFG. Regular Languages I.e., the language accepted by an FAs NPDA is context-free. regular expressions EFAs NFAs For details, see Sipser 2.2 or Kozen 24-25. right-linear grammars DFAs Pushdown Automata 27-12 6 Deterministic PDAs (DPDAs) Like an NPDA except: • Have a special symbol ( ) for the end of input. • Transition relation must be a function (no choices/guessing!) Effectively a DPDA = DFA + stack operations, except that some transitions might not read any input (and instead perform stack operations). For details, see Kozen Supplementary Lecture F. Pushdown Automata 27-13 Where do DPDAs Fit In? The language of a DPDA is a Context-Free Languages (CFLs) Deterministic Context-Free Language (DCFL). CFGs NPDAs DCFLs are a proper subset of CFLs. Deterministic Context-Free Languages (DCFLs) I.e., there are CFLs that are DPDAs not DCFLS. E.g. {aibjck | i = j or i = k} Regular Languages R FAs {ww | w in {0, 1}*} regular EFAs I.e. DPDAs are strictly less expressions powerful than NPDAs. NFAs right-linear DFAs Unlike CFLs, DCFLs are closed under grammars complement. Pushdown Automata 27-14 7.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    7 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us