![Page 1: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/1.jpg)
1
Positive Propertiesof
Context-Free languages
![Page 2: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/2.jpg)
2
Context-free languages are closed under: Union
1L is context free
2L is context free
21 LL
is context-free
![Page 3: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/3.jpg)
3
Union Example:
|11 baSS
|| 222 bbSaaSS
Union grammar:
}{1nnbaL
}{2RwwL
21 | SSS }{}{ Rnn wwbaL
![Page 4: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/4.jpg)
4
In general:
Take any two context-free grammarswith start variables 21, SS
The union grammar has start variable 21 | SSS
G
21,GG
and )()()( 21 GLGLGL
is context-free
![Page 5: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/5.jpg)
5
Context-free languages are closed under: Concatenation
1L is context free
2L is context free
21LL
is context-free
![Page 6: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/6.jpg)
6
Concatenation Example:
|11 baSS
|| 222 bbSaaSS
Concatenation grammar:
}{1nnbaL
}{2RwwL
21SSS }}{{ Rnn wwbaL
![Page 7: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/7.jpg)
7
In general:
Take any two context-free grammarswith start variables 21, SS
The concatenation grammar has start variable 21 | SSS
G
21,GG
and )()()( 21 GLGLGL is context-free
![Page 8: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/8.jpg)
8
Context-free languages are closed under: Star-operation
L is context free *L is context-free
![Page 9: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/9.jpg)
9
Star operation Example:
|aSbS
Star grammar:
}{ nnbaL
|11 SSS *}{ nnbaL
![Page 10: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/10.jpg)
10
In general:
Take any context-free grammarswith start variable S
The concatenation grammar has start variable
1G
G
and *)()( 1 GLGL is context-free
|11 SSS
![Page 11: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/11.jpg)
11
Negative Propertiesof
Context-Free Languages
![Page 12: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/12.jpg)
12
Context-free languagesare not closed under: intersection
1L is context free
2L is context free
21 LL
not necessarilycontext-free
![Page 13: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/13.jpg)
13
Counter Example:
}{1mnn cbaL
|
|
cCC
aAbA
ACS
Context-free:
}{2mmn cbaL
|
|
bBbB
aAA
ABS
Context-free:
}{21nnn cbaLL NOT context-free
![Page 14: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/14.jpg)
14
Context-free languagesare not closed under: complement
L is context free L not necessarilycontext-free
![Page 15: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/15.jpg)
15
Counter Example:
}{1mnn cbaL
|
|
cCC
aAbA
ACS
Context-free:
}{2mmn cbaL
|
|
bBbB
aAA
ABS
Context-free:
}{2121nnn cbaLLLL
NOT context-free
![Page 16: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/16.jpg)
16
Intersectionof
Context-free languagesand
Regular Languages
![Page 17: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/17.jpg)
17
The intersection of a context-free language and a regular languageis a context-free language
1L context free
2L regular
21 LL
context-free
![Page 18: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/18.jpg)
18
1Lfor for 2LNPDA
1M
DFA
2M
Construct a new NPDA machinethat accepts
Machine Machine
M
21 LL
context-free regular
M simulates in parallel and 1M 2M
![Page 19: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/19.jpg)
19
1M 2M
1q 2qcba ,
transition
1p 2pa
transition
NPDA DFA
11, pq cba ,
transition
MNPDA
22 , pq
![Page 20: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/20.jpg)
20
1M 2M
0q
initial state
0p
initial state
NPDA DFA
Initial state
MNPDA
00 , pq
![Page 21: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/21.jpg)
21
1M 2M
1q
final state
1p
final states
NPDA DFA
final states
MNPDA
11, pq
2p
21, pq
![Page 22: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/22.jpg)
22
M simulates in parallel and 1M 2M
M accepts string w if and only if
accepts string and w1M
accepts string w2M
)()()( 21 MLMLML
![Page 23: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/23.jpg)
23
Therefore: )()( 21 MLML
(since is NPDA) M
is context-free
21 LL is context-free
![Page 24: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/24.jpg)
24
Example Applications of Regular Closure
Prove that: }100:{ nbaL nn
is context-free
![Page 25: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/25.jpg)
25
}{ nnbaWe know:
is context-free
![Page 26: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/26.jpg)
26
}{ 1001001 baL is regular
}{}){( 100100*1 babaL is regular
We also know:
![Page 27: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/27.jpg)
27
}{}){( 100100*1 babaL
is regular
}{ nnba
is context-free
1}{ Lba nn
is context-free
1}{
}100:{
Lba
nbaLnn
nn
is context-free
![Page 28: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/28.jpg)
28
Another application
Prove that: }:{ cba nnnwL
is not context-free
![Page 29: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/29.jpg)
29
}:{ cba nnnwL
}{*}**{ nnn cbacbaL
context-free regular Is context-free
If is context-free
Then
Impossible!!!
Therefore, is not context free L
![Page 30: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/30.jpg)
30
Decidable Propertiesof
Context-Free Languages
![Page 31: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/31.jpg)
31
Membership Question:
for grammarfind if string
G)(GLw
![Page 32: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/32.jpg)
32
Membership Question:
for grammarfind if string
G)(GLw
Membership Algorithms:
Parsers
Exhaustive search parser
CYKparsing algorithm
![Page 33: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/33.jpg)
33
Empty Language Question:
for grammar find if
G)(GL
![Page 34: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/34.jpg)
34
Empty Language Question:
for grammar find if
G)(GL
Algorithm:
Check if start variable is useless S
Remove useless variables
![Page 35: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/35.jpg)
35
Infinite Language Question:
for grammar find if is infinite
G)(GL
![Page 36: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/36.jpg)
36
Infinite Language Question:
for grammar find if is infinite
G)(GL
Algorithm:
• Remove useless variables• Remove unit and lambda productions
• Create the dependency graph for variables
• If there is a loop in the dependency graph the language is infinite
![Page 37: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/37.jpg)
37
Example:
cBSC
bbbBB
aaCbA
ABS
|
|
S
A
B
C
Dependency graph infinite
![Page 38: 1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free](https://reader030.vdocuments.site/reader030/viewer/2022033107/56649d3a5503460f94a14c0e/html5/thumbnails/38.jpg)
38
cBSC
bbbBB
aaCbA
ABS
|
|
acbbSbbbacBSbBaCbBABS
ii bbbSacbb
bbbSacbbacbbSbbbS
)()(
)()( 22