1 / 69

NPDA’s Accept Context-Free Languages

Learn how to convert any context-free grammar into a nondeterministic pushdown automaton (NPDA) in order to simulate leftmost derivations.

essiemartin
Télécharger la présentation

NPDA’s Accept Context-Free Languages

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. NPDA’s Accept Context-Free Languages COMP 335

  2. Theorem: Context-Free Languages (Grammars) Languages Accepted by NPDAs COMP 335

  3. Proof - Step 1: Context-Free Languages (Grammars) Languages Accepted by NPDAs Convert any context-free grammar to a NPDA with: COMP 335

  4. Proof - Step 2: Context-Free Languages (Grammars) Languages Accepted by NPDAs Convert any NPDA to a context-free grammar with: COMP 335

  5. Proof - step 1 ConvertingContext-Free Grammarsto NPDAs COMP 335

  6. We will convert any context-free grammar to an NPDA automaton Such that: Simulates leftmost derivations of COMP 335

  7. Leftmost derivation Input processed Stack contents leftmost variable Stack Simulation of derivation Input COMP 335

  8. Leftmost derivation string of terminals Stack Simulation of derivation Input end of input is reached COMP 335

  9. An example grammar: What is an equivalent NPDA? COMP 335

  10. Grammar: NPDA: COMP 335

  11. Grammar: A leftmost derivation: COMP 335

  12. Derivation: Input Time 0 Stack COMP 335

  13. Derivation: Input Time 0 Stack COMP 335

  14. Derivation: Input Time 1 Stack COMP 335

  15. Derivation: Input Time 2 Stack COMP 335

  16. Derivation: Input Time 3 Stack COMP 335

  17. Derivation: Input Time 4 Stack COMP 335

  18. Derivation: Input Time 5 Stack COMP 335

  19. Derivation: Input Time 6 Stack COMP 335

  20. Derivation: Input Time 7 Stack COMP 335

  21. Derivation: Input Time 8 Stack COMP 335

  22. Derivation: Input Time 9 Stack accept COMP 335

  23. In general: Given any grammar We can construct a NPDA With COMP 335

  24. Constructing NPDA from grammar : For any terminal For any production COMP 335

  25. Grammar generates string if and only if NPDA accepts COMP 335

  26. Therefore: For any context-free language there is a NPDA that accepts the same language Context-Free Languages (Grammars) Languages Accepted by NPDAs COMP 335

  27. Proof - step 2 ConvertingNPDAstoContext-Free Grammars COMP 335

  28. For any NPDA we will construct a context-free grammar with COMP 335

  29. Intuition: The grammar simulates the computation of the machine A derivation in Grammar : terminals variables Input processed Stack contents Current configuration in NPDA COMP 335

  30. Some Necessary Modifications • Modify (if necessary) the NPDA so that: • 1) The stack is never empty • 2) has a single final state and empties • the stack when it accepts a string • 3) Has transitions in a special form: • (qi,a,A)={c1,c2,…,cn}, where ci=(qj,) or ci=(qj,BC) COMP 335

  31. Example of a NPDA in correct form: COMP 335

  32. The Grammar Construction In grammar : Stack symbol Variables: states Terminals: Input symbols of NPDA COMP 335

  33. For each transition We add production COMP 335

  34. For each transition We add productions For all possible states in the automaton COMP 335

  35. Stack bottom symbol Start Variable: Start state final state COMP 335

  36. Example: Grammar production: COMP 335

  37. Example: Grammar productions: COMP 335

  38. Example: Grammar production: COMP 335

  39. Resulting Grammar: COMP 335

  40. COMP 335

  41. Derivation of string COMP 335

  42. In general: if and only if the NPDA goes from to by reading string and the stack doesn’t change below and then is removed from stack COMP 335

  43. Therefore: if and only if is accepted by the NPDA COMP 335

  44. Therefore: For any NPDA there is a context-free grammar that accepts the same language Context-Free Languages (Grammars) Languages Accepted by NPDAs COMP 335

  45. Deterministic PDADPDA COMP 335

  46. Deterministic PDA: DPDA Allowed transitions: (deterministic choices) COMP 335

  47. Allowed transitions: (deterministic choices) COMP 335

  48. Not allowed: (non deterministic choices) COMP 335

  49. DPDA example COMP 335

  50. The language is deterministic context-free COMP 335

More Related