310 likes | 318 Views
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.
E N D
Simplifications of Context-Free Grammars Dr. Sandip Mal
Useless Production Some derivations never terminate... Useless Productions Dr. Sandip Mal
Useless Production Another grammar: Not reachable from S Dr. Sandip Mal
Nullable Variables Nullable Variable: Example: Nullable variable Dr. Sandip Mal
Unit-Productions Unit Production: (a single variable in both sides) Example: Unit Productions Dr. Sandip Mal
Normal FormsforContext-free Grammars Dr. Sandip Mal
Chomsky Normal Form Each productions has form: or variable variable terminal Dr. Sandip Mal
Examples: Chomsky Normal Form Not Chomsky Normal Form Dr. Sandip Mal
Conversion to Chomsky Normal Form • Example: Not Chomsky Normal Form We will convert it to Chomsky Normal Form Dr. Sandip Mal
Introduce new variables for the terminals: Dr. Sandip Mal
Introduce new intermediate variable to break first production: Dr. Sandip Mal
Introduce intermediate variable: Dr. Sandip Mal
Final grammar in Chomsky Normal Form: Initial grammar Dr. Sandip Mal
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
The Procedure • First remove: • Nullable variables • Unit productions (Useless variables optional) Dr. Sandip Mal
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
Replace any production with New intermediate variables: Dr. Sandip Mal
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
Greinbach Normal Form All productions have form: symbol variables Dr. Sandip Mal
Examples: Greinbach Normal Form Not Greinbach Normal Form Dr. Sandip Mal
Conversion to Greinbach Normal Form: Greinbach Normal Form Dr. Sandip Mal
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