1 / 31

Simplifications of Context-Free Grammars

Learn about simplifications of context-free grammars by Dr. Sandip Mal, including useless productions, nullable variables, unit productions, Chomsky normal form, and Greibach normal form. Discover conversion techniques and the importance of different grammar forms.

allisona
Download Presentation

Simplifications of 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. Simplifications of Context-Free Grammars Dr. Sandip Mal

  2. Dr. Sandip Mal

  3. Useless Production Some derivations never terminate... Useless Productions Dr. Sandip Mal

  4. Useless Production Another grammar: Not reachable from S Dr. Sandip Mal

  5. Nullable Variables Nullable Variable: Example: Nullable variable Dr. Sandip Mal

  6. Unit-Productions Unit Production: (a single variable in both sides) Example: Unit Productions Dr. Sandip Mal

  7. Dr. Sandip Mal

  8. Dr. Sandip Mal

  9. Dr. Sandip Mal

  10. Dr. Sandip Mal

  11. Dr. Sandip Mal

  12. Dr. Sandip Mal

  13. Dr. Sandip Mal

  14. Dr. Sandip Mal

  15. Normal FormsforContext-free Grammars Dr. Sandip Mal

  16. Chomsky Normal Form Each productions has form: or variable variable terminal Dr. Sandip Mal

  17. Examples: Chomsky Normal Form Not Chomsky Normal Form Dr. Sandip Mal

  18. Conversion to Chomsky Normal Form • Example: Not Chomsky Normal Form We will convert it to Chomsky Normal Form Dr. Sandip Mal

  19. Introduce new variables for the terminals: Dr. Sandip Mal

  20. Introduce new intermediate variable to break first production: Dr. Sandip Mal

  21. Introduce intermediate variable: Dr. Sandip Mal

  22. Final grammar in Chomsky Normal Form: Initial grammar Dr. Sandip Mal

  23. In general: From any context-free grammar (which doesn’t produce ) not in Chomsky Normal Form we can obtain: an equivalent grammar in Chomsky Normal Form Dr. Sandip Mal

  24. The Procedure • First remove: • Nullable variables • Unit productions (Useless variables optional) Dr. Sandip Mal

  25. Then, for every symbol : New variable: Add production In productions with length at least 2 replace with Productions of form do not need to change! Dr. Sandip Mal

  26. Replace any production with New intermediate variables: Dr. Sandip Mal

  27. Observations • Chomsky normal forms are good • for parsing and proving theorems • It is easy to find the Chomsky normal • form for any context-free grammar Dr. Sandip Mal

  28. Greinbach Normal Form All productions have form: symbol variables Dr. Sandip Mal

  29. Examples: Greinbach Normal Form Not Greinbach Normal Form Dr. Sandip Mal

  30. Conversion to Greinbach Normal Form: Greinbach Normal Form Dr. Sandip Mal

  31. Observations • Greinbach normal forms are very good • for parsing strings (better than Chomsky Normal Forms) • However, it is difficult to find the • Greinbach normal of a grammar Dr. Sandip Mal

More Related