1 / 42

COSC 3340: Introduction to Theory of Computation

Explore the conversion process from Pushdown Automata to Context-Free Grammar explained using examples and rules in lecture 14 by Dr. Verma at University of Houston. Simplified steps and important considerations are covered.

baileyt
Download Presentation

COSC 3340: Introduction to Theory of 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. COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 14 UofH - COSC 3340 - Dr. Verma

  2. PDA’s and CFG’s • For every CFG G there is a PDA M such that L(G) = L(M) • For every PDA M there is a CFG G such that L(M) = L(G) UofH - COSC 3340 - Dr. Verma

  3. CFG  PDA • Given CFG G = (V, , R, S) • Let PDA M = (Q, ,   V  {$}, , qstart, {qaccept}) • Q = {qstart, qloop,qaccept} •  contains transitions for the form • ((qstart,, ), (qloop, S$))   • For each rule A  w  R(G) there is a transition ((qloop,, A),(qloop, w))   *** • For each symbol    ((qloop, , ), (qloop, ))   • ((qloop,, $), (qaccept, ))   , S$ qstart ,   , A w qloop , $  qaccept UofH - COSC 3340 - Dr. Verma

  4. CFG  PDA • The PDA simulates a leftmost derivation of the string. • Place the marker symbol $ and the start variable on the stack. • Repeat the following steps forever (a) If the top of stack is a variable symbol A, nondeterministically select on of the rules for A and substitute A by the string on the right-hand side of the rule. (b) If the top of stack is terminal symbol , read the next symbol from the input and compare it to . If they match, repeat. If they do not match, reject on this branch of the nondeterminism. (c) If the top of stack is the symbol $, enter the accept state. Doing so accepts the input if it has all been read. UofH - COSC 3340 - Dr. Verma

  5. Example: S  aSb |  Z is used instead of $  Instead of  q0 = qstart q1 = qloop q2 = qaccept UofH - COSC 3340 - Dr. Verma

  6. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  7. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  8. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  9. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  10. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  11. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  12. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  13. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  14. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  15. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  16. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  17. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  18. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  19. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  20. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  21. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  22. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  23. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  24. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  25. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  26. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  27. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  28. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  29. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  30. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  31. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  32. Idea of PDA  CFG • First, we simplify our task by modifying P slightly to give it the following three features • It has a single accept state, qaccept. • It empties its stack before accepting. • Each transition either pushes a symbol onto the stack (a push move) or pops one off the stack (a pop move), but does not do both at the same time. UofH - COSC 3340 - Dr. Verma

  33. Idea of PDA  CFG • Apq generates all strings that take PDA, P, from p to q, starting and ending with empty stack. • For any string x, P’s first move on x must be a push (why?) and last move must be a pop (why?). • Two possibilities occur during P’s computation on x: either the symbol popped at the end is the symbol pushed at beginning, or not. • The first type of rule simulates the first possibility • The second type of rule simulates the second. UofH - COSC 3340 - Dr. Verma

  34. PDA  CFG • Say that P = {Q, , , , q0, {qaccept}} and construct G. The variable of G are {Apq| p, q Q}. The start variable is Aq0qaccept. Now we describe G’s rules. • For each p, q, r, s Q, t  , and a, b  , if (p, a, ) contains (r, t) and (s, b, t) contains (q, ) put the rule Apq aArsb in G. • For each p, q, r  Q put the rule Apq AprArq in G. • Finally, for each p  Q put the rule App  in G. UofH - COSC 3340 - Dr. Verma

  35. Example • Let M be the PDA for {anbn | n > 0} • Note that n cannot be 0, which makes the example a little simpler. M = {{p, q}, {a, b}, {a}, , p, {q}}, where  = {((p, a, ),(p, a)),((p, b, a), (q, )),((q, b, a),(q, ))} p q UofH - COSC 3340 - Dr. Verma

  36. Example: contd. • CFG, G = (V, {a, b}, Apq, R) corresponding to M has V = {App, Apq, Aqp, Aqq}. R contains the following rules: • Type I: • Apq aAppb • Apq aApqb • Type II: • App App App| Apq Aqp • Apq App Apq| Apq Aqq • Aqp Aqq Aqp| Aqp App • Aqq Aqq Aqq| Aqp Apq • Type III: • App  • Aqq  We can discard all rules containing the variables Aqq and Aqp. And we can also simplify the rules containing App and get the grammar with just two rules Apqab and Apq  aApqb. UofH - COSC 3340 - Dr. Verma

  37. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  38. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  39. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  40. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  41. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

  42. JFLAP SIMULATION UofH - COSC 3340 - Dr. Verma

More Related