A language that can be generated by a CFG.
A language is context-free iff there exists a CFG such that it generates . All regular languages are context-free.
Properties
If and are CFLs, then the following are also CFLs:
- Union
- Concatenation
- Kleene star
The following are not necessarily CFLs:
- Intersection
- Complementation
Examples
Palindrome
Language of palindromes over . are palindromes.
If is palindrome then and are palindromes.
This language is not regular, but context-free.
a^n b^n
Language of strings with equal number of a’s followed by b’s.
Grammar:
This language is not regular, but context-free.
Syntax of Programming Languages
Programming languages (such as Python, Java) have syntax that can be described by CFGs. Used in compiler design to parse code and check for syntax errors.