Simplifications of Context-Free Grammars - PowerPoint PPT Presentation

About This Presentation
Title:

Simplifications of Context-Free Grammars

Description:

unit productions. 35. For every symbol : Add new variable. In productions, replace with ... Conversion to Greinbach Normal Form. Greinbach. Normal Form. 41. Theorem: ... – PowerPoint PPT presentation

Number of Views:14
Avg rating:3.0/5.0
Slides: 50
Provided by: costas
Learn more at: http://www.cs.rpi.edu
Category:

less

Transcript and Presenter's Notes

Title: Simplifications of Context-Free Grammars


1
Simplifications of Context-Free Grammars

2
A Substitution Rule
equivalent grammar
substitute B
3
In general
substitute B
equivalent grammar
4
Useless Productions
5
never terminates...
6
Useless Production
7
Another grammar
8
Not reachable from S
Useless Production
9
In general
If
Then
is useful
is useless
Otherwise
10
Removing Useless Productions
Example Grammar
11
First
find all variables that produce strings with only
terminals
Round 1
Round 2
12
Keep only the variables that produce terminal
symbols
13
Second
Find all variables reachable from S
Dependency Graph
not reachable
14
Keep only the variables reachable from S
Final Grammar
15
Nullable Variables
Nullable Variable
16
Removing Nullable Variables
Example Grammar
Nullable variable
17
Substitute
Final Grammar
18
Unit-Productions
Unit Production
19
Removing Unit Productions
Observation
Is removed immediately
20
Example Grammar
21
substitute
22
(No Transcript)
23
substitute
24
Remove repeated productions
Final grammar
25
Removing All
  • 1. Remove Nullable Variables
  • 2. Remove Unit-Productions
  • 3. Remove Useless Variables

26
Normal FormsforContext-free Grammars

27
Chomsky Normal Form
All productions have form
OR
variable
variable
terminal
28
Examples
NOT
Chomsky Normal Form
Chomsky Normal Form
29
Convertion to Chomsky Normal Form
  • Example

NOT
Chomsky Normal Form
30
Introduce variables for terminals
31
Introduce intermediate variables
32
Final grammar in Chomsky Normal Form
Initial grammar
33
In general
From any context-free grammar Not in
Chomsky Normal Form
We can obtain An equivalent grammar
in Chomsky Normal Form
34
The Procedure
Remove nullable variables unit productions
35
For every symbol
Add new variable
Add production
In productions, replace with
36
Replace any production
with
New variables
37
Theorem
For any context-free grammar there is an
equivalent grammar in Chomsky Normal Form
38
Greinbach Normal Form
All rules have form
variables
symbol
39
Examples
NOT
Greinbach Normal Form
Greinbach Normal Form
40
Conversion to Greinbach Normal Form
Greinbach Normal Form
41
Theorem
For any context-free grammar
there is an equivalent grammar in Greinbach
Normal Form
42
An ApplicationofChomsky Normal Forms
43
The CYK Membership Algorithm
Inputs
  • Grammar
  • in Chomsky Normal Form
  • String w

Output
find if
44
Algorithm Input Examples
Grammar
String
45
(No Transcript)
46
(No Transcript)
47
(No Transcript)
48
(No Transcript)
49
Therefore
Time Complexity
It can be easily converted to a parser
Write a Comment
User Comments (0)
About PowerShow.com