In formal language theory, a context-free language is a language generated by some context-free grammar. The set of all context-free languages is identical to the set of languages accepted by pushdown automata.
Contents |
An archetypical context-free language is , the language of all non-empty even-length strings, the entire first halves of which are 's, and the entire second halves of which are 's. is generated by the grammar , and is accepted by the pushdown automaton where is defined as follows:
where is initial stack symbol and means pop action.
Context-free languages have many applications in programming languages; for example, the language of all properly matched parentheses is generated by the grammar . Also, most arithmetic expressions are generated by context-free grammars.
Context-free languages are closed under the following operations. That is, if L and P are context-free languages, the following languages are context-free as well:
Context-free languages are not closed under complement, intersection, or difference. However, if L is a context-free language and D is a regular language then both their intersection and their difference are context-free languages.
The context-free languages are not closed under intersection. This can be seen by taking the languages and , which are both context-free. Their intersection is , which can be shown to be non-context-free by the pumping lemma for context-free languages.
Context-free languages are also not closed under complementation, as for any languages A and B: .
The following problems are undecidable for arbitrary context-free grammars A and B:
The following problems are decidable for arbitrary context-free languages:
|