Simplifications of ContextFree Grammars 1 A Substitution Rule
Simplifications of Context-Free Grammars 1
A Substitution Rule equivalent grammar substitute B 2
In general: substitute B equivalent grammar 3
Useless Productions 4
never terminates. . . 5
Useless Production 6
Another grammar: 7
Not reachable from S Useless Production 8
In general: If Then Otherwise is useful is useless 9
Removing Useless Productions Example Grammar 10
First: find all variables that produce strings with only terminals Round 1: Round 2: 11
Keep only the variables that produce terminal symbols 12
Second: Find all variables reachable from S Dependency Graph not reachable 13
Keep only the variables reachable from S Final Grammar 14
Nullable Variables Nullable Variable: 15
Removing Nullable Variables Example Grammar: Nullable variable 16
Substitute Final Grammar 17
Unit-Productions Unit Production: 18
Removing Unit Productions Observation: Is removed immediately 19
Example Grammar: 20
substitute 21
22
substitute 23
Remove repeated productions Final grammar 24
Removing All 1. Remove Nullable Variables 2. Remove Unit-Productions 3. Remove Useless Variables 25
Normal Forms for Context-free Grammars 26
Chomsky Normal Form All productions have form: OR variable terminal 27
Examples: Chomsky Normal Form NOT Chomsky Normal Form 28
Convertion to Chomsky Normal Form Example: NOT Chomsky Normal Form 29
Introduce variables for terminals: 30
Introduce intermediate variables: 31
Final grammar in Chomsky Normal Form: Initial grammar 32
In general: From any context-free grammar Not in Chomsky Normal Form We can obtain: An equivalent grammar in Chomsky Normal Form 33
The Procedure: Remove nullable variables unit productions 34
For every symbol : Add new variable Add production In productions, replace with 35
Replace any production: with: New variables: 36
Theorem: For any context-free grammar there is an equivalent grammar in Chomsky Normal Form 37
Greinbach Normal Form All rules have form: symbol variables 38
Examples: Greinbach Normal Form NOT Greinbach Normal Form 39
Conversion to Greinbach Normal Form 40
Theorem: For any context-free grammar there is an equivalent grammar in Greinbach Normal Form 41
An Application of Chomsky Normal Forms 42
The CYK Membership Algorithm Inputs: • Grammar in Chomsky Normal Form • String w Output: find if 43
Algorithm: Input Examples Grammar String : : 44
45
46
47
48
Therefore: Time Complexity: It can be easily converted to a parser 49
- Slides: 49