Professional Documents
Culture Documents
Languages
Closure property of CFG
Union
Context-free languages
are closed under: Union
L is context free
1 L1 L2
L2 is context free is context-free
Example
Language Grammar
n n
L1 {a b } S1 aS1b
|
L2 {ww } R S2 aS2a |
bS2b |
n n
L {a b } Union
R
{ww } S S1 | S2
In general:
For context-free languages L1, L2
with context-free grammars
and start variables
G1, G2
It is assumed that variable sets of G1Sand
1, SG2
2 are
disjoint
Context-free languages
are closed under: Concatenation
L is context free
1 L1L2
L2 is context free is context-free
Example
Language Grammar
n n
L1 {a b } S1 aS1b
|
L2 {ww } R S2 aS2a | bS2b
|
Concatenation
n n
L {a b }{ww } R S S1S 2
In general:
Context-free languages
are closed under: Star-operation
is context-free
L is context free L
*
Example
Language Grammar
n n
L {a b } S aSb
|
Star Operation
L {a n bn }* S1 SS1 |
In general:
S
The grammar of the star operation L
has new start variable S1 *
and additional production
S1 SS1 |
Negative properties of Context-
Free Languages
Intersection
Context-free languages
are not closed under: intersection
L is context free
1 L1 L2
n n m n m m
L1 {a b c } L2 {a b c }
Context-free: Context-free:
S AC S AB
A aAb A. aA |
| B. bBc
C cC | |
Intersection
L1 L2 {a n b n c n } NOT context-
Complement
Context-free languages
are not closed under: complement
n n m n m m
L1 {a b c } L2 {a b c }
Context-free: Context-free:
S AC S AB
A aAb | A. aA |
C cC | B. bBc
Complement |
L1 L1 L2
NOT context-
n n n
{a b c }
The Pumping Lemma
for
Context-Free
Languages
Non-context free languages
n n n
{a b c : n 0}
Context-free languages
n n
{a b : n
0}