Other meanings of Context-free language
Formal language theory
A context-free language is a class of formal languages that can be generated by a context-free grammar and recognized by a pushdown automaton.1 These languages occupy a central position in the Chomsky hierarchy, being strictly more expressive than regular languages but less powerful than context-sensitive languages.2 They are fundamental to the description of programming languages, natural language syntax, and markup languages such as XML and HTML.
A context-free language is defined as the set of strings generated by a context-free grammar (CFG) — a tuple (V, Σ, R, S) where V is a finite set of nonterminal symbols, Σ a finite alphabet of terminals, R a finite set of production rules of the form A → α with A ∈ V and α ∈ (V ∪ Σ)*, and S ∈ V the start symbol. Equivalently, it is the language accepted by a nondeterministic pushdown automaton (PDA) by final state or empty stack.1 The class of context-free languages is closed under union, concatenation, Kleene star, and reversal, but not under intersection or complement. The pumping lemma for context-free languages provides a necessary (but not sufficient) condition for a language to be context-free, often used to prove that certain languages are not context-free, such as {aⁿbⁿcⁿ | n ≥ 0}.2
Context-free languages are precisely those that can be recognized by pushdown automata, which use a single stack to store unbounded information.1 They are closed under substitution, homomorphism, and inverse homomorphism, but not under intersection with regular languages (though the intersection of a context-free language with a regular language is context-free). A famous result is that the emptiness, finiteness, and membership problems are decidable for context-free languages, but the equivalence problem is undecidable. The class includes the well-known language of balanced parentheses, {aⁿbⁿ | n ≥ 0}, and arithmetic expressions. However, it excludes languages requiring two independent counting mechanisms, such as {aⁿbⁿcⁿ} or {ww | w ∈ {a,b}*}.
Context-free grammars are the backbone of most programming language definitions and compiler front ends, where they specify the syntax of languages like C, Java, and Python. In natural language processing, context-free grammar (often augmented with features) models the syntactic structure of sentences, though the full complexity of human language may exceed context-freeness.3 Markup languages such as SGML, XML, and HTML are defined by context-free grammars, enabling machine parsing and validation. The theory also underpins the design of recursive descent parsers and the LL(k) and LR(k) families of parsing algorithms.
While the classic Dyck language of balanced parentheses is context-free, the language of strings with an equal number of a's and b's is also context-free, but the language of strings with twice as many a's as b's is not.2 A surprising result is that the determinism of context-free languages (those recognized by deterministic pushdown automata) is a proper subclass — e.g., the language of palindromes over {a,b} is context-free but not deterministic.1 The intersection of two context-free languages can be context-sensitive but not context-free, illustrating the limits of the class. Another niche fact: the language {aⁿbⁿcⁿ} is context-sensitive, but the language {aⁿbⁿcⁿdⁿ} is not context-sensitive in the usual hierarchy, though it is in the indexed grammar class. The Chomsky–Schützenberger theorem characterizes context-free languages as the homomorphic images of the Dyck language, a deep structural result.
The concept of context-free languages was introduced by Noam Chomsky in 1956 as part of his work on the Chomsky hierarchy.
Help improve the encyclopedia. Reports go straight to the site manager.