Title: Normal Forms for Context-free Grammars
1Normal FormsforContext-free Grammars
2Chomsky Normal Form
All productions have form
and
variable
variable
terminal
3Examples
Chomsky Normal Form
Not Chomsky Normal Form
4Convertion to Chomsky Normal Form
Not Chomsky Normal Form
5Introduce variables for terminals
6Introduce intermediate variable
7Introduce intermediate variable
8Final grammar in Chomsky Normal Form
Initial grammar
9In general
From any context-free grammar not in Chomsky
Normal Form
we can obtain An equivalent grammar
in Chomsky Normal Form
10The Procedure
First remove Nullable variables Unit
productions
11For every symbol
Add production
In productions replace with
New variable
12Replace any production
with
New intermediate variables
13Theorem
For any context-free grammar there is an
equivalent grammar in Chomsky Normal Form
14Observations
- Chomsky normal forms are good
- for parsing and proving theorems
- It is very easy to find the Chomsky normal
- form of any context-free grammar
15Greinbach Normal Form
All productions have form
symbol
variables
16Examples
Greinbach Normal Form
Not Greinbach Normal Form
17Conversion to Greinbach Normal Form
Greinbach Normal Form
18Theorem
For any context-free grammar there is an
equivalent grammar in Greinbach Normal Form
19Observations
- Greinbach normal forms are very good
- for parsing
- It is hard to find the Greinbach normal
- form of any context-free grammar
20An ApplicationofChomsky Normal Forms
21The CYK Membership Algorithm
Input
- Grammar in Chomsky Normal Form
Output
find if
22The Algorithm
Input example
23(No Transcript)
24(No Transcript)
25(No Transcript)
26(No Transcript)
27Therefore
Time Complexity
Observation
The CYK algorithm can be easily converted to a
parser
28Pushdown AutomataPDAs
29Pushdown Automaton -- PDA
Input String
Stack
States
30Initial Stack Symbol
Stack
Stack
bottom
special symbol
31The States
Pop symbol
Input symbol
Push symbol
32input
stack
top
Replace
33input
stack
top
Push
34input
stack
top
Pop
35input
stack
top
No Change
36Non-Determinism
37NPDA Non-Deterministic PDA
Example
38Execution Example
Time 0
Input
Stack
current state
39Time 1
Input
Stack
40Time 2
Input
Stack
41Time 3
Input
Stack
42Time 4
Input
Stack
43Time 5
Input
Stack
44Time 6
Input
Stack
45Time 7
Input
Stack
46Time 8
Input
Stack
accept
47A string is accepted if
- All the input is consumed
- The last state is a final state
We do not care about the stack contents
48The input string is accepted by the NPDA
49In general,
is the language accepted by the NPDA
50Another NPDA example
NPDA
51Execution Example
Time 0
Input
Stack
52Time 1
Input
Stack
53Time 2
Input
Stack
54Time 3
Input
Stack
55Time 4
Input
Stack
56Time 5
Input
Stack
57Time 6
Input
Stack
accept