![]() |
VOOZH | about |
Context-Free Languages (CFLs) form an important class of languages in automata theory and formal language theory. These languages are generated using context-free grammars (CFGs) and are recognized by pushdown automata (PDAs).
CFLs are closed under the following operations:
If L and M are two context-free languages, then their union L ∪ M is also a CFL.
Construction:
Example: Let L₁ = { aⁿbⁿcᵐ | m ≥ 0, n ≥ 0 } and L₂ = { aⁿbᵐcᵐ | n ≥ 0, m ≥ 0 }.
- L₁ enforces that the number of a’s equals the number of b’s.
- L₂ enforces that the number of b’s equals the number of c’s.
- Their union states that either of these conditions must be satisfied, making the resulting language context-free.
Note: So CFL are closed under Union.
If L and M are CFLs, then their concatenation LM is also a CFL.
Construction:
Example
- L₁ ensures the number of a’s equals b’s.
- L₂ ensures the number of c’s equals d’s.
- Their concatenation states that first a’s equal b’s, then c’s equal d’s, making the language context-free.
Note: So CFL are closed under Concatenation.
If L is a CFL, then its Kleene closure L* (zero or more repetitions of strings in L) is also a CFL.
Construction:
- L1 = { anbn | n >= 0 }
- L1* = { anbn | n >= 0 }* is also context free.
Note :So CFL are closed under Kleene Closure.
If L1 and If L2 are two context free languages, their intersection L1 ? L2 need not be context free.
Example
- L₁ ensures the number of a’s equals b’s (c’s independent).
- L₂ ensures the number of b’s equals c’s (a’s independent).
- Their intersection requires a = b = c, which PDA cannot handle.
Hence, the language is not context-free.
Note : So CFL are not closed under Intersection and Complementation.
If L is a CFL, then its reversal L^R (where each string is reversed) is also a CFL.
Construction:
- Original Grammar: S → 0S1 | 01
- Reversed Grammar: S → 1S0 | 10
A homomorphism is a function that replaces each symbol in a string with another string.
If L is a CFL and h is a homomorphism, then h(L) is also a CFL.
👁 homomorphism_closed_
- Let G have the production S → 0S1 | 01.
- Define a homomorphism h(0) = ab, h(1) = ε.
- Then, h(L(G)) will be generated by a new grammar with productions: S → abS | ab
This shows that CFLs are closed under homomorphism.
If L is a CFL and h is a homomorphism, then h⁻¹(L) is also a CFL.
Construction:
Deterministic CFL are subset of CFL which can be recognized by Deterministic PDA. Deterministic PDA has only one move from a given state and input symbol, i.e., it do not have choice. For a language to be DCFL it should be clear when to PUSH or POP.
Hence, L₁ is a DCFL.
Note : DCFL are closed only under complementation and Inverse Homomorphism.
Therefore, L₃ requires an NPDA for acceptance.
Hence, L₃ is context-free but not deterministic context-free (CFL but not DCFL).