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