normal forms for context-free grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · theorem:...
TRANSCRIPT
![Page 1: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/1.jpg)
1
Normal Formsfor
Context-free Grammars
![Page 2: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/2.jpg)
Linz 6th, Section 6.2
“Two Important Normal Forms,”
pages 171--178
2
![Page 3: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/3.jpg)
3
Chomsky Normal Form
All productions have form:
BCA
variable variable
aAand
terminal
![Page 4: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/4.jpg)
4
Examples:
bA
SAA
aS
ASS
Not Chomsky
Normal Form
aaA
SAA
AASS
ASS
Chomsky
Normal Form
![Page 5: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/5.jpg)
5
Conversion to Chomsky Normal Form
Example:
AcB
aabA
ABaS
Not Chomsky
Normal Form
![Page 6: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/6.jpg)
6
AcB
aabA
ABaS
Introduce variables for terminals:
cT
bT
aT
ATB
TTTA
ABTS
c
b
a
c
baa
a
cba TTT ,,
![Page 7: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/7.jpg)
7
Introduce intermediate variable:
cT
bT
aT
ATB
TTTA
ABTS
c
b
a
c
baa
a
cT
bT
aT
ATB
TTTA
BTV
AVS
c
b
a
c
baa
a
1
1
1V
![Page 8: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/8.jpg)
8
Introduce intermediate variable:
cT
bT
aT
ATB
TTV
VTA
BTV
AVS
c
b
a
c
ba
a
a
2
2
1
1
2V
cT
bT
aT
ATB
TTTA
BTV
AVS
c
b
a
c
baa
a
1
1
![Page 9: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/9.jpg)
9
Final grammar in Chomsky Normal Form:
cT
bT
aT
ATB
TTV
VTA
BTV
AVS
c
b
a
c
ba
a
a
2
2
1
1
AcB
aabA
ABaS
Initial grammar
![Page 10: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/10.jpg)
10
From any context-free grammar
not in Chomsky Normal Form
we can obtain:
An equivalent grammar
in Chomsky Normal Form
In general:
![Page 11: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/11.jpg)
11
The Procedure
First remove:
Nullable variables
Unit productions
![Page 12: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/12.jpg)
12
For every symbol : a
In productions: replace with a aT
Add production aTa
New variable: aT
![Page 13: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/13.jpg)
13
Replace any productionnCCCA 21
with
nnn CCV
VCV
VCA
12
221
11
New intermediate variables: 221 ,,, nVVV
![Page 14: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/14.jpg)
14
Theorem: For any context-free grammar G such that the empty string is not in L(G), there is an equivalent grammar in Chomsky Normal Form
Linz, 6th, Theorem 6.6, page 172.
![Page 15: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/15.jpg)
15
Observations
• 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
![Page 16: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/16.jpg)
16
Greibach Normal Form
All productions have form:
kVVVaA 21
symbol variables
0k
![Page 17: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/17.jpg)
17
Examples:
bB
bbBaAA
cABS
||
Greibach
Normal Form
aaS
abSbS
Not Greibach
Normal Form
![Page 18: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/18.jpg)
18
aaS
abSbS
Conversion to Greibach Normal Form:
bT
aT
aTS
STaTS
b
a
a
bb
Greibach
Normal Form
![Page 19: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/19.jpg)
19
Theorem: For any context-free grammar
G such that the empty string is not in L(G), there is an equivalent grammar
in Greibach Normal Form
Linz, 6th, Theorem 6.7, page 176.Proof not given because it is too
complicated.
![Page 20: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/20.jpg)
20
Observations
• Greibach normal forms are very good
for parsing
• It is hard to find the Greibach normal
form of any context-free grammar
![Page 21: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/21.jpg)
21
An Applicationof
Chomsky Normal Forms
![Page 22: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/22.jpg)
22
The CYK Membership Algorithm
J. Cocke, D. H. Younger, and T. KasamiInput:
• Grammar in Chomsky Normal Form G
• String
Output:
find if )(GLw
w
![Page 23: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/23.jpg)
Considers every possible consecutive subsequence of letters and sets K∈T[i,j] if the sequence of letters starting from i to j can be generated from the non-terminal K.
Once it has considered sequences of length
1, it goes on to sequences of length 2, and so on.
23
![Page 24: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/24.jpg)
For subsequences of length 2 and greater, it considers every possible partition of the subsequence into two halves, and checks to see if there is some production A-> BC such that B matches the first half and C Matches the second half. If so, it records A as matching the whole subsequence.
Once this process is completed, the sentence is recognized by the grammar if the entire string is matched by the start symbol.
24
![Page 25: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/25.jpg)
25
The Algorithm
• Grammar :G
bB
ABB
aA
BBA
ABS
• String : w aabbb
Input example:
![Page 26: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/26.jpg)
26
[0:1]
[1:2] [2:3] [3:4] [4:5]
[0:2] [1:3] [2:4] [3:5]
[0:3] [1:4] [2:5]
[0:4] [1:5]
[0:5]
aabbb
![Page 27: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/27.jpg)
27
a a b b b
aa ab bb bb
aab abb bbb
aabb abbb
aabbb
aabbb
![Page 28: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/28.jpg)
28
a
A
a
A
b
B
b
B
b
B
aa ab bb bb
aab abb bbb
aabb abbb
aabbb
bB
ABB
aA
BBA
ABS
![Page 29: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/29.jpg)
29
a
A
a
A
b
B
b
B
b
B
aa ab
S,B
bb
A
bb
A
aab abb bbb
aabb abbb
aabbb
bB
ABB
aA
BBA
ABS
![Page 30: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/30.jpg)
30
a
A
a
A
b
B
b
B
b
B
aa ab
S,B
bb
A
bb
A
aab
S,B
abb
A
bbb
S,B
aabb
A
abbb
S,B
aabbb
S,B
bB
ABB
aA
BBA
ABS
![Page 31: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/31.jpg)
31
Therefore: )(GLaabbb
Time Complexity:3|| w
The CYK algorithm can be
easily converted to a parser
Observation:
![Page 32: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/32.jpg)
32
Pushdown AutomataPDAs
![Page 33: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/33.jpg)
33
Pushdown Automaton -- PDA
Input String
Stack
States
![Page 34: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/34.jpg)
34
Initial Stack Symbol
Stack
$
Stack
z
bottomspecial symbol
![Page 35: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/35.jpg)
35
The States
q1 q2a, b c
Input
symbol
Pop
symbolPush
symbol
![Page 36: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/36.jpg)
36
q1 q2a, b c
a
b top
input
stack
a
Replaceeh
$eh
$
c
![Page 37: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/37.jpg)
37
q1 q2a, c
a a
Pushb
eh
$eh
$
b
c
top
input
stack
![Page 38: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/38.jpg)
38
q1 q2a, b
a a
Popb
eh
$eh
$
top
input
stack
![Page 39: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/39.jpg)
39
q1 q2a,
a a
No Changeb
eh
$eh
$
btop
input
stack
![Page 40: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/40.jpg)
40
Non-Determinism
q1
q2a, b c
q3a, b c
q1 q2, b c
transition
These are allowed transitions in
a Non-deterministic PDA (NPDA)
![Page 41: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/41.jpg)
41
NPDA: Non-Deterministic PDA
Example:
,
a, a
b, aq0 q1 q2 q3
b, a
, $ $
![Page 42: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/42.jpg)
42
a, a
b, a0q q1 q2 q3
Execution Example:
Input
a a a b b b
current
state
b, a
Time 0
, , $ $
Stack
$
![Page 43: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/43.jpg)
43
a, a
b, aq0 q1 q2 q3
Input
a a a b b b
b, a
Time 1
, , $ $
Stack
$
![Page 44: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/44.jpg)
44
a, a
b, aq0 q1 q2 q3
Input
Stack
a a a b b b
$
a
b, a
Time 2
, , $ $
![Page 45: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/45.jpg)
45
a, a
b, aq0 q1 q2 q3
Input
Stack
a a a b b b
$
a
a
b, a
Time 3
, , $ $
![Page 46: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/46.jpg)
46
a, a
b, aq0 q1 q2 q3
Input
Stack
a a a b b b
$
a
a
a
b, a
Time 4
, , $ $
![Page 47: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/47.jpg)
47
a, a
b, aq0 q1 q2 q3
Input
a a a b b b
Stack
$
a
a
a
b, a
Time 5
, , $ $
![Page 48: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/48.jpg)
48
a, a
b, aq0 q1 q2 q3
Input
a a a b b b
$
a
Stack
b, a
Time 6
, , $ $
a
![Page 49: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/49.jpg)
49
a, a
b, aq0 q1 q2 q3
Input
a a a b b b
$
Stack
b, a
Time 7
, , $ $
a
![Page 50: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/50.jpg)
50
a, a
b, aq0 q1 q2 q3
Input
a a a b b b
b, a
Time 8
accept
, , $ $
$
Stack
![Page 51: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/51.jpg)
51
A string is accepted if there is
a computation such that:
• All the input is consumed
• The last state is a final state
At the end of the computation,
we do not care about the stack contents
![Page 52: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/52.jpg)
52
The input string
is accepted by the NPDA:
aaabbb
a, a
b, aq0 q1 q2 q3
b, a
, , $ $
![Page 53: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/53.jpg)
53
}0:{ nbaL nn
is the language accepted by the NPDA:
a, a
b, aq0 q1 q2 q3
b, a
In general,
, , $ $
![Page 54: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/54.jpg)
54
Another NPDA example
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
NPDA M
}{)( RwwML
![Page 55: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/55.jpg)
55
Execution Example:
Input
Time 0
Stack
$
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
a ab b
![Page 56: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/56.jpg)
56
Input
a ab
Time 1
Stack
$
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
ab
![Page 57: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/57.jpg)
57
Input
Time 2
Stack
$
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
aa ab b
b
![Page 58: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/58.jpg)
58
Input
Time 3
Stack
$
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
aa ab b
b
Guess the middle
of string
![Page 59: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/59.jpg)
59
Input
Time 4
Stack
$
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
aa ab b
b
![Page 60: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/60.jpg)
60
Input
Time 5
Stack
$
, $ $1q q2
bb
aa
,
,
, q0
bb
aa
,
,
a ab b a
![Page 61: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/61.jpg)
61
Input
Time 6
Stack
$
, $ $q1
bb
aa
,
,
, q0
bb
aa
,
,
a ab b
accept
q2
![Page 62: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/62.jpg)
62
Rejection Example:
Input
Time 0
Stack
$
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
a b b b
![Page 63: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/63.jpg)
63
Input
Time 1
Stack
$
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
aa b b b
![Page 64: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/64.jpg)
64
Input
Time 2
Stack
$
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
a
ba b b b
![Page 65: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/65.jpg)
65
Input
Time 3
Stack
$
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
a
b
Guess the middle
of string
a b b b
![Page 66: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/66.jpg)
66
Input
Time 4
Stack
$
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
a
ba b b b
![Page 67: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/67.jpg)
67
Input
Time 5
Stack
$
, $ $1q q2
bb
aa
,
,
, q0
bb
aa
,
,
aa b b b
There is no possible transition.
Input is not consumed
![Page 68: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/68.jpg)
68
Another computation on same string:
Input Time 0
Stack
$
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
a b b b
![Page 69: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/69.jpg)
69
Input
Time 1
Stack
$
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
aa b b b
![Page 70: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/70.jpg)
70
Input
Time 2
Stack
$
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
a
ba b b b
![Page 71: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/71.jpg)
71
Input
Time 3
Stack
$
a
ba b b b
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
b
![Page 72: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/72.jpg)
72
Input
Time 4
Stack
a b b b
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
$
a
b
b
b
![Page 73: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/73.jpg)
73
Input
Time 5
Stack
a b b b
$
a
b
b
b
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
No final state
is reached
![Page 74: Normal Forms for Context-free Grammarsryan/cse4083/busch/class10.pdf · 2017. 2. 22. · Theorem: For any context-free grammar G such that the empty string is not in L(G), there is](https://reader033.vdocument.in/reader033/viewer/2022060713/6079fe0ee970f35fae178497/html5/thumbnails/74.jpg)
74
, $ $q1
q2
bb
aa
,
,
, q0
bb
aa
,
,
There is no computation
that accepts string abbb
)(MLabbb