Pushdown Automata (PDA) Part 2 While I am distributing graded exams: Design a PDA to accept L = { a m b n : m  n; m, n > 0} MA/CSSE 474 Theory of Computation.

Slides:



Advertisements
Similar presentations
Context-Free and Noncontext-Free Languages
Advertisements

Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Pushdown Automata Chapter 12. Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Pushdown Automata Part II: PDAs and CFG Chapter 12.
PDAs => CFGs Sipser 2.2 (pages ). Last time…
PDAs => CFGs Sipser 2.2 (pages ). Last time…
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
1 Converting NPDAs to Context-Free Grammars. 2 For any NPDA we will construct a context-free grammar with.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
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.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Final Exam Review Cummulative Chapters 0, 1, 2, 3, 4, 5 and 7.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
Pushdown Automata.
Pushdown Automata (PDA) Intro
TM Design Universal TM MA/CSSE 474 Theory of Computation.
Pushdown Automata (PDAs)
Design contex-free grammars that generate: L 1 = { u v : u ∈ {a,b}*, v ∈ {a, c}*, and |u| ≤ |v| ≤ 3 |u| }. L 2 = { a p b q c p a r b 2r : p, q, r ≥ 0 }
Context-free Languages Chapter 2. Ambiguity.
Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.
Pushdown Automata Part I: PDAs Chapter Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2)
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2010.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
Context-Free and Noncontext-Free Languages Chapter 13 1.
Equivalence of Pushdown Automata and Context-Free Grammar Prof. Héctor Muñoz-Avila.
DETERMINISTIC CONTEXT FREE LANGUAGES
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
PushDown Automata. What is a stack? A stack is a Last In First Out data structure where I only have access to the last element inserted in the stack.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
Context-Free and Noncontext-Free Languages Chapter 13.
Formal Languages, Automata and Models of Computation
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
1 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations pop, push, and nop. PDAs always.
Bottom-up parsing Pumping Theorem for CFLs MA/CSSE 474 Theory of Computation.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Theory of Computation Automata Theory Dr. Ayman Srour.
Week 14 - Friday.  What did we talk about last time?  Simplifying FSAs  Quotient automata.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Formal Languages, Automata and Models of Computation
Table-driven parsing Parsing performed by a finite state machine.
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz
PDAs Accept Context-Free Languages
Chapter 7 PUSHDOWN AUTOMATA.
Bottom-up parsing Pumping Theorem for CFLs
Pushdown Automata (PDA) Part 2
… NPDAs continued.
Pumping Theorem for CFLs
More About Nondeterminism
Presentation transcript:

Pushdown Automata (PDA) Part 2 While I am distributing graded exams: Design a PDA to accept L = { a m b n : m  n; m, n > 0} MA/CSSE 474 Theory of Computation

Your Questions? Previous class days' material Reading Assignments HW10 or 11 problems Exam 2 problems Anything else

L = { a m b n : m  n; m, n > 0} ● State 4: Clear the input ● State 3: Clear the stack ● A non-deterministic machine! What if we could detect end of input (as we can in real-world situations)? detect empty stack? ● Add end-of-input marker $ to Σ ● Add bottom-of-stack marker # to Γ

Reducing Nondeterminism ● Original non-deterministic model ● With the markers:

The Power of Nondeterminism Consider A n B n C n = { a n b n c n : n  0}. PDA for it?

The Power of Nondeterminism Consider A n B n C n = { a n b n c n : n  0}. PDA for it? Now consider L =  A n B n C n. L is the union of two languages: 1. {w  { a, b, c }* : the letters are out of order}, and 2. { a i b j c k : i, j, k  0 and (i  j or j  k)} (in other words, unequal numbers of a ’s, b ’s, and c ’s).

A PDA for L =  A n B n C n

Are the Context-Free Languages Closed Under Complement?  A n B n C n is context free. If the CF languages were closed under complement, then  A n B n C n = A n B n C n would also be context-free. But we will prove that it is not.

L = { a n b m c p : n, m, p  0 and n  m or m  p} S  NC/* n  m, then arbitrary c 's S  QP/* arbitrary a 's, then p  m N  A/* more a 's than b 's N  B/* more b 's than a 's A  a A  a A A  a A b B  b B  B b B  a B b C   | c C/* add any number of c 's P  B'/* more b 's than c 's P  C'/* more c 's than b 's B'  b B'  b B' B'  b B' c C'  c | C' c C'  C' c C'  b C' c Q   | a Q/* prefix with any number of a 's

More on PDAs A PDA for {ww R : w  {a, b}*}: What about a PDA to accept {ww : w  { a, b }*}?

PDAs and Context-Free Grammars Theorem: The class of languages accepted by PDAs is exactly the class of context-free languages. Recall: context-free languages are languages that can be defined with context-free grammars. Restate theorem: Can describe with context-free grammar Can accept by PDA

Going One Way Lemma: Each context-free language is accepted by some PDA. Proof (by construction): The idea: Let the stack do the work. Two approaches: Top down Bottom up

Top Down The idea: Let the stack keep track of expectations. Example: Arithmetic expressions E  E + T E  T T  T  F T  F F  (E) F  id (1) (q, , E), (q, E+T)(7) (q, id, id), (q,  ) (2) (q, , E), (q, T)(8) (q, (, ( ), (q,  ) (3) (q, , T), (q, T*F)(9) (q, ), ) ), (q,  ) (4) (q, , T), (q, F)(10) (q, +, +), (q,  ) (5) (q, , F), (q, (E) )(11) (q, ,  ), (q,  ) (6) (q, , F), (q, id)

A Top-Down Parser The outline of M is: M = ({p, q}, , V, , p, {q}), where  contains: ● The start-up transition ((p, ,  ), (q, S)). ● For each rule X  s 1 s 2 …s n. in R, the transition: ((q, , X), (q, s 1 s 2 …s n )). ● For each character c  , the transition: ((q, c, c), (q,  )).

Example of the Construction L = { a n b * a n } 0 (p, ,  ), (q, S) (1)S   * 1 (q, , S), (q,  ) (2)S  B 2 (q, , S), (q, B) (3)S  a S a 3 (q, , S), (q, a S a ) (4)B   4 (q, , B), (q,  ) (5)B  b B 5 (q, , B), (q, b B) 6 (q, a, a ), (q,  ) input = a a b b a a 7 (q, b, b ), (q,  ) transstate unread inputstack p a a b b a a  0 q a a b b a a S 3 q a a b b a aa S a 6 q a b b a a S a 3 q a b b a aa S aa 6 q b b a a S aa 2 q b b a a B aa 5 q b b a ab B aa 7 q b a a B aa 5 q b a ab B aa 7 q a a B aa 4 q a aaa 6 q aa 6 q 

Another Example L = { a n b m c p d q : m + n = p + q} 0 (p, ,  ), (q, S) (1)S  a S d 1 (q, , S), (q, a S d ) (2)S  T2 (q, , S), (q, T) (3)S  U3 (q, , S), (q, U) (4)T  a T c 4 (q, , T), (q, a T c ) (5)T  V5 (q, , T), (q, V) (6)U  b U d 6 (q, , U), (q, b U d ) (7)U  V7 (q, , U), (q, V) (8)V  b V c 8 (q, , V), (q, b V c ) (9)V   9 (q, , V), (q,  ) 10 (q, a, a ), (q,  ) 11 (q, b, b ), (q,  ) input = a a b c c d 12 (q, c, c ), (q,  ) 13 (q, d, d ), (q,  ) transstate unread input stack

The Other Way to Build a PDA - Directly L = { a n b m c p d q : m + n = p + q} (1) S  a S d (6) U  b U d (2) S  T (7) U  V (3) S  U (8) V  b V c (4) T  a T c (9) V   (5) T  V input = a a b c d d

The Other Way to Build a PDA - Directly L = { a n b m c p d q : m + n = p + q} (1) S  a S d (6) U  b U d (2) S  T (7) U  V (3) S  U (8) V  b V c (4) T  a T c (9) V   (5) T  V input = a a b c d d 1234 a//aa//ab//ab//ac/a/c/a/ d/a/d/a/ b//ab//ac/a/c/a/ d/a/d/a/ c/a/c/a/ d/a/d/a/ d/a/d/a/

Notice the Nondeterminism Machines constructed with the algorithm are often nondeterministic, even when they needn't be. This happens even with trivial languages. Example: A n B n = { a n b n : n  0} A grammar for A n B n is:A PDA M for A n B n is: (0) ((p, ,  ), (q, S)) [1] S  a S b (1) ((q, , S), (q, a S b )) [2] S   (2) ((q, , S), (q,  )) (3) ((q, a, a ), (q,  )) (4) ((q, b, b ), (q,  )) But transitions 1 and 2 make M nondeterministic. A directly constructed machine for A n B n can be deterministic. Constructing deterministic top-down parsers major topic in CSSE 404.

Bottom-Up (1) E  E + T (2) E  T (3) T  T  F (4) T  F (5) F  (E) (6) F  id Reduce Transitions: (1) (p, , T + E), (p, E) (2) (p, , T), (p, E) (3) (p, , F  T), (p, T) (4) (p, , F), (p, T) (5) (p, , )E( ), (p, F) (6) (p, , id), (p, F) Shift Transitions (7) (p, id,  ), (p, id) (8) (p, (,  ), (p, () (9) (p, ),  ), (p, )) (10) (p, +,  ), (p, +) (11) (p, ,  ), (p,  ) The idea: Let the stack keep track of what has been found. Example: id + id * id. (Do the derivation first)

A Bottom-Up Parser The outline of M is: M = ({p, q}, , V, , p, {q}), where  contains: ● The shift transitions: ((p, c,  ), (p, c)), for each c  . ● The reduce transitions: ((p, , (s 1 s 2 …s n.) R ), (p, X)), for each rule X  s 1 s 2 …s n. in G. Un does an application of this rule. ● The finish up transition: ((p, , S), (q,  )). A top-down parser discovers a leftmost derivation of the input string (If any). Bottom-up discovers rightmost derivation (in reverse order)