TOC Lecture 14
TOC Lecture 14
Properties of CFL
Closure Properties
Closure Properties
• Context-free languages are closed under:
– Union
– Concatenation
• Example:
− Let L1 = { anbn , n > 0}. Corresponding grammar G1 will have
P: S1 aAb | ab
− Let L2 = { cmdm , m ≥ 0}. Corresponding grammar G2 will have
P: S2 cBd | ε
− Union of L1 and L2 , L = L1 ∪ L2 = { anbn } ∪ { cmdm }
− The corresponding grammar G will have the additional
production : S S1 | S2
Concatenation
• Let L1 and L2 be two context free languages. Then L1L2 is also
context free.
• Example:
− Let L1 = { anbn , n > 0}. Corresponding grammar G1 will have
P: S1 aAb | ab
− Let L2 = { cmdm , m ≥ 0}. Corresponding grammar G2 will have
P: S2 cBd | ε
− Concatenation of L1 and L2 , L = L1L2 = { anbncmdm }
− The corresponding grammar G will have the additional
production: S S1 S2
Kleene Star
• If L is a context free language, then L* is also context free.
• Example: