You are on page 1of 23

Property of Context Free

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

The grammar of the union L1


L2
has new start variable S
and additional production S S1 | S 2
Concatenation

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:

For context-free languages L1, L2


with context-free grammars
and start variables
G1, G2
S1, S2

The grammar of the concatenation L1L


has new start variable S
2
and additional production S SS1 2
Star Operation

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:

For context-free language L


with context-free grammar
and start variable
G

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

L2 is context free not


necessarily
context-free
Example

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

L is context free L not


necessarily
context-free
Example

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}

You might also like