490 likes | 505 Views
Learn how to apply substitution rules, remove useless and nullable productions, eliminate unit productions, convert to normal forms (Chomsky and Greibach), and apply the CYK Membership Algorithm. Master the process to enhance and streamline context-free grammars efficiently.
E N D
A Substitution Rule equivalent grammar substitute B
In general: substitute B equivalent grammar
never terminates...
Not reachable from S Useless Production
In general: If Then is useful Otherwise is useless
Removing Useless Productions Example Grammar
First: find all variables that produce strings with only terminals Round 1: Round 2:
Keep only the variables that produce terminal symbols
Second: Find all variables reachable from S Dependency Graph not reachable
Keep only the variables reachable from S Final Grammar
Nullable Variables Nullable Variable:
Removing Nullable Variables Example Grammar: Nullable variable
Substitute Final Grammar
Unit-Productions Unit Production:
Removing Unit Productions Observation: Is removed immediately
Remove repeated productions Final grammar
Removing All • 1. Remove Nullable Variables • 2. Remove Unit-Productions • 3. Remove Useless Variables
Chomsky Normal Form All productions have form: OR variable variable terminal
Examples: Chomsky Normal Form NOT Chomsky Normal Form
Convertion to Chomsky Normal Form • Example: NOT Chomsky Normal Form
Final grammar in Chomsky Normal Form: Initial grammar
In general: From any context-free grammar Not in Chomsky Normal Form We can obtain: An equivalent grammar in Chomsky Normal Form
The Procedure: • Remove • nullable variables • unit productions
For every symbol : Add new variable Add production In productions, replace with
Replace any production: with: New variables:
Theorem: For any context-free grammar there is an equivalent grammar in Chomsky Normal Form
Greinbach Normal Form All rules have form: variables symbol
Examples: NOT Greinbach Normal Form Greinbach Normal Form
Conversion to Greinbach Normal Form Greinbach Normal Form
Theorem: For any context-free grammar there is an equivalent grammar in Greinbach Normal Form
The CYK Membership Algorithm Inputs: • Grammar • in Chomsky Normal Form • String w Output: find if
Algorithm: Input Examples Grammar : String :
Therefore: Time Complexity: It can be easily converted to a parser