1 / 43

Converting NPDAs to Context-Free Grammars

Converting NPDAs to Context-Free Grammars. For any NPDA. we will construct a context-free grammar with. Intuition:. The grammar simulates the machine. A derivation in Grammar :. Current configuration in NPDA. A derivation in Grammar :. terminals. variables.

pbarbour
Download Presentation

Converting NPDAs to Context-Free Grammars

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. Converting NPDAstoContext-Free Grammars

  2. For any NPDA we will construct a context-free grammar with

  3. Intuition: The grammar simulates the machine A derivation in Grammar : Current configuration in NPDA

  4. A derivation in Grammar : terminals variables Input processed Stack contents in NPDA

  5. Some Necessary Modifications • First, we modify the NPDA: • It has a single final state • It empties the stack • when it accepts the input Empty Stack Original NPDA

  6. Second, we modify the NPDA transitions: • all transitions will have form or

  7. Example of a NPDA in correct form:

  8. The Grammar Construction stack symbol In grammar variables have form states Terminals are input symbols

  9. For each transition We add production For all states

  10. For each transition We add production For all states in the NPDA

  11. Stack bottom symbol Start Variable: Start state final state

  12. Example: Grammar production:

  13. Example: Grammar productions:

  14. Example: Grammar production:

  15. Resulting Grammar:

  16. Derivation of string

  17. In general, in grammar if and only if is accepted by the NPDA

  18. Explanation: By construction of grammar: If and only if in the NPDA going from to the stack doesn’t change below and is removed from stack

  19. Deterministic PDAs(DPDAs)

  20. DPDAs • Allowed Transitions:

  21. Not allowed: Not allowed even when is

  22. Allowed:

  23. Not allowed: Not allowed even when is

  24. DPDA example

  25. The language is deterministic context-free

  26. In general: A language is deterministic context-free if there is some NPDA that accepts it

  27. Example of Non-DPDA

  28. Not allowed transitions for DPDAs

  29. NPDAs have more power thanDPDAs

  30. We will show: There is (accepted by a NPDA) a context-free language which is not (not accepted by a DPDA) deterministic context-free

  31. The language is:

  32. The language is context-free Context-free grammar for : (there is an NPDA that accepts )

  33. Theorem: The language is not deterministic context-free (there is no DPDA that accepts )

  34. Proof: Assume for contradiction that is deterministic context free Therefore: There exists a DPDA that accepts

  35. The DPDA with accepts accepts

  36. A fact: The language is not context-free (we will prove it at the next class)

  37. Another fact: The language is not context-free

  38. We will construct a NPDA that accepts

  39. First, we modify : Replace with Modified

  40. The NPDA that accepts Modified Original

  41. is accepted by a NPDA Therefore: is context-free Contradiction! ( is not context-free)

  42. Therefore: There is no DPDA that accepts End of Proof

More Related