prof. busch - lsu1 properties of context-free languages
TRANSCRIPT
![Page 1: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/1.jpg)
Prof. Busch - LSU 1
Propertiesof
Context-Free languages
![Page 2: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/2.jpg)
Prof. Busch - LSU 2
Context-free languages are closed under: Union
1L is context free
2L is context free
21 LL
is context-free
Union
![Page 3: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/3.jpg)
Prof. Busch - LSU 3
Example
|11 baSS
|| 222 bbSaaSS
Union
}{1nnbaL
}{2RwwL
21 | SSS }{}{ Rnn wwbaL
Language Grammar
![Page 4: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/4.jpg)
Prof. Busch - LSU 4
In general:
The grammar of the union has new start variableand additional production 21 | SSS
For context-free languageswith context-free grammarsand start variables
21, LL
21, GG
21, SS
21 LL S
![Page 5: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/5.jpg)
Prof. Busch - LSU 5
Context-free languages are closed under: Concatenation
1L is context free
2L is context free
21LL
is context-free
Concatenation
![Page 6: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/6.jpg)
Prof. Busch - LSU 6
Example
|11 baSS
|| 222 bbSaaSS
Concatenation
}{1nnbaL
}{2RwwL
21SSS }}{{ Rnn wwbaL
Language Grammar
![Page 7: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/7.jpg)
Prof. Busch - LSU 7
In general:
The grammar of the concatenation has new start variableand additional production 21SSS
For context-free languageswith context-free grammarsand start variables
21, LL
21, GG
21, SS
21LLS
![Page 8: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/8.jpg)
Prof. Busch - LSU 8
Context-free languages are closed under: Star-operation
L is context free*L is context-free
Star Operation
![Page 9: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/9.jpg)
Prof. Busch - LSU 9
|aSbS }{ nnbaL
|11 SSS *}{ nnbaL
Example
Language Grammar
Star Operation
![Page 10: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/10.jpg)
Prof. Busch - LSU 10
In general:
The grammar of the star operation has new start variableand additional production
For context-free languagewith context-free grammarand start variable
LGS
*L1S
|11 SSS
![Page 11: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/11.jpg)
Prof. Busch - LSU 11
Negative Propertiesof
Context-Free Languages
![Page 12: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/12.jpg)
Prof. Busch - LSU 12
Context-free languagesare not closed under: intersection
1L is context free
2L is context free
21 LL
not necessarilycontext-free
Intersection
![Page 13: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/13.jpg)
Prof. Busch - LSU 13
Example
}{1mnn cbaL
|
|
cCC
aAbA
ACS
Context-free:
}{2mmn cbaL
|
|
bBcB
aAA
ABS
Context-free:
}{21nnn cbaLL NOT context-free
Intersection
![Page 14: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/14.jpg)
Prof. Busch - LSU 14
Context-free languagesare not closed under: complement
L is context free L not necessarilycontext-free
Complement
![Page 15: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/15.jpg)
Prof. Busch - LSU 15
}{2121nnn cbaLLLL
NOT context-free
Example
}{1mnn cbaL
|
|
cCC
aAbA
ACS
Context-free:
}{2mmn cbaL
|
|
bBcB
aAA
ABS
Context-free:
Complement
![Page 16: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/16.jpg)
Prof. Busch - LSU 16
Intersectionof
Context-free languagesand
Regular Languages
![Page 17: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/17.jpg)
Prof. Busch - LSU 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: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/18.jpg)
Prof. Busch - LSU 18
1Lfor for 2LNPDA
1M
DFA
2M
Construct a new NPDA machinethat accepts
Machine Machine
M21 LL
context-free regular
M simulates in parallel and 1M 2M
![Page 19: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/19.jpg)
Prof. Busch - LSU 19
1M 2M
1q 2qcba ,
transition
1p 2pa
transition
NPDA DFA
11, pq cba ,
transition
MNPDA
22 , pq
![Page 20: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/20.jpg)
Prof. Busch - LSU 20
1M 2M
1q 2qcb,
transition
1p
NPDA DFA
11, pq cb,
transition
MNPDA
12, pq
![Page 21: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/21.jpg)
Prof. Busch - LSU 21
1M 2M
0q
initial state
0p
initial state
NPDA DFA
Initial state
MNPDA
00 , pq
![Page 22: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/22.jpg)
Prof. Busch - LSU 22
1M 2M
1q
final state
1p
final states
NPDA DFA
final states
MNPDA
11, pq
2p
21, pq
![Page 23: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/23.jpg)
Prof. Busch - LSU 23
Example:
, , ,
1, b1, a
1,d1,c
0q 1q 2q 3q
1M
}},{,},{|,|||:{ *2
*121211 dcwbawwwwwL
NPDA
context-free
![Page 24: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/24.jpg)
Prof. Busch - LSU 24
0p
2M
*2 },{ caL
ca,
DFA
regular
![Page 25: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/25.jpg)
Prof. Busch - LSU 25
Automaton for: }0:{21 ncaLL nn
, , ,
1, a 1,c
00, pq 01, pq 02, pq 03, pq
NPDA M
context-free
![Page 26: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/26.jpg)
Prof. Busch - LSU 26
M simulates in parallel and 1M 2M
M accepts string w if and only if
accepts string and w1M
accepts string w2M
)()()( 21 MLMLML
In General:
![Page 27: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/27.jpg)
Prof. Busch - LSU 27
Therefore:
)()( 21 MLML
is NPDAM
is context-free
21 LL is context-free
![Page 28: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/28.jpg)
Prof. Busch - LSU 28
Applications of
Regular Closure
![Page 29: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/29.jpg)
Prof. Busch - LSU 29
The intersection of a context-free language and a regular languageis a context-free language
1L context free
2L regular
21 LL
context-free
Regular Closure
![Page 30: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/30.jpg)
Prof. Busch - LSU 30
An Application of Regular Closure
Prove that: }0,100:{ nnbaL nn
is context-free
![Page 31: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/31.jpg)
Prof. Busch - LSU 31
}0:{ nba nn
We know:
is context-free
![Page 32: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/32.jpg)
Prof. Busch - LSU 32
}{ 1001001 baL is regular
}{}){( 100100*1 babaL is regular
We also know:
![Page 33: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/33.jpg)
Prof. Busch - LSU 33
}{}){( 100100*1 babaL
regular
}{ nnbacontext-free
1}{ Lba nn context-free
LnnbaLba nnnn }0,100:{}{ 1
is context-free
(regular closure)
![Page 34: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/34.jpg)
Prof. Busch - LSU 34
Another Application of Regular Closure
Prove that: }:{ cba nnnwL
is not context-free
![Page 35: Prof. Busch - LSU1 Properties of Context-Free languages](https://reader036.vdocuments.us/reader036/viewer/2022062407/56649d355503460f94a0bdfe/html5/thumbnails/35.jpg)
Prof. Busch - LSU 35
}:{ cba nnnwL
}{*}**{ nnn cbacbaL
context-free regular context-free
If is context-free
Then
Impossible!!!
Therefore, is not context free L
(regular closure)