1 / 44

Regular Grammars Generate Regular Languages

Regular Grammars Generate Regular Languages. Theorem. Regular grammars generate exactly the class of regular languages: If is a regular grammar then is a regular language. If is a regular language then there is a regular grammar with. Proof. First we prove:

geraldinew
Download Presentation

Regular Grammars Generate Regular 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. Regular Grammars GenerateRegular Languages

  2. Theorem • Regular grammars generate exactly the • class of regular languages: • If is a • regular grammar • then is • a regular language If is a regular language then there is a regular grammar with

  3. Proof • First we prove: • If is a • regular grammar • then is • a regular language can be: Right-linear grammar or Left-linear grammar

  4. The case of Right-Linear Grammars • Let be a right-linear grammar • We will show: is regular • The proof: • We will construct an NFA • with

  5. Grammar is right-linear Example:

  6. Construct NFA such that • every state is a variable: special final state

  7. Add edges for each production:

  8. NFA Grammar

  9. In General • A right-linear grammar • has variables: • and productions: or

  10. We construct the NFA such that: • each variable corresponds to a node:

  11. For each production: • we add transitions and intermediate nodes ………

  12. For each production: • we add transitions and intermediate nodes ………

  13. Resulting NFA looks like this:

  14. Now, we need to show:

  15. The Case: • Take We will show: there is a path with label in from state to state …………

  16. Grammar looks like: strings

  17. ……

  18. …… ……

  19. …… …… …… ……

  20. Since: • We have: …… …… …… ……

  21. Since: • We have: • We have: and ……

  22. The Case: Take We will show that in

  23. Since • there is a path ……

  24. Write: • There is a path …… …… …… ……

  25. Since: • This derivation is possible …… …… …… ……

  26. Since: • We have: • We have:

  27. The Case of Left-Linear Grammars • Let be a left-linear grammar • We will show: is regular • The proof: • We will construct a right-linear • grammar with

  28. Since is left-linear grammar the productions look like:

  29. Construct right-linear grammar In : In :

  30. In : In :

  31. It is easy to see that: • Since is right-linear, we have: • is regular language • is regular language (homework) • is regular language

  32. Proof - Part 2 • Now we will prove: If is a regular language then there is a regular grammar with Proof outline: we will take an NFA for and convert it to a regular grammar

  33. Since is regular • There is an NFA such that Example:

  34. Convert to a right-linear grammar

  35. We can generalize this process for • any regular language : • For any regular language • we obtain an right-linear grammar • with

  36. Since is right-linear grammar • is also a regular grammar • with

More Related