formal languages
The Chomsky Hierarchy
You should know: context free grammars, turing machines
Overview
The Chomsky hierarchy, introduced by linguist Noam Chomsky in 1956, classifies formal grammars — and the languages they generate — into four nested classes of increasing expressive power: regular, context-free, context-sensitive, and unrestricted (recursively enumerable). Each class corresponds to a natural machine model of matching computational power: finite automata, pushdown automata, linear-bounded automata, and Turing machines, respectively. The hierarchy gives a unifying map of computation and language, showing exactly how much extra machinery (memory structure) is needed to generate or recognize progressively richer sets of strings.
Intuition
Think of the hierarchy as four increasingly generous rulebooks for rewriting symbols into strings. Type 3 (regular) grammars are the strictest — each rule can only replace a single symbol with one symbol followed optionally by one more symbol, so they can't 'remember' unbounded nesting; they correspond to finite automata. Type 2 (context-free) grammars relax this — a single symbol can expand into any string — enabling nested nested structure, matched by a pushdown automaton's stack. Type 1 (context-sensitive) allows rewriting a symbol differently depending on its surrounding context, needing a machine whose memory is bounded only by the input's own length (a linear-bounded automaton). Type 0 (unrestricted) grammars allow completely arbitrary rewriting rules and are exactly as powerful as a full Turing machine — anything computable at all.
Formal Definition
The four grammar types are defined by restrictions on production rules α → β (where α, β are strings of terminals and nonterminals, and α must contain at least one nonterminal):
Notation
| Notation | Meaning |
|---|---|
| The set of nonterminal (variable) symbols in the grammar | |
| The set of terminal symbols (the alphabet of the generated strings) | |
| A production rule rewriting string α as string β |
Theorems
Applications
Worked Examples
It requires counting an unbounded matching quantity (needs a stack, ruling out Type 3) but no context-dependent rewriting beyond simple nested matching (a single context-free rule S → aSb | ε suffices, so it doesn't need the full power of Type 1 or Type 0).
Answer: It is context-free (Type 2) — generated by the simple grammar S → aSb | ε, and recognized by a pushdown automaton, but not regular.
Practice Problems
Why does programming language syntax typically sit at the context-free (Type 2) level rather than being fully regular (Type 3)?
Which machine model corresponds to context-sensitive (Type 1) languages?
A compiler team notices their language's grammar is context-free, but one of their semantic rules ('every variable must be declared before use') cannot be expressed as a context-free production rule. What does this reveal about the limits of the grammar level they chose, and how do real compilers handle it?
Common Mistakes
Thinking 'context-sensitive' grammar rules are just context-free rules with more complicated right-hand sides.
The defining feature of context-sensitive rules is that a nonterminal's expansion CAN depend on the symbols surrounding it (αAβ → αγβ), whereas context-free rules (A → γ) must apply regardless of context — that dependency on surrounding symbols is what the name refers to.
Believing the four Chomsky hierarchy classes are the only possible language classes in computability theory.
The hierarchy is a particularly clean and historically important four-level classification, but computability theory and complexity theory contain a much finer landscape of classes (e.g. deterministic vs. nondeterministic context-free, various complexity classes within Type 0) beyond these four.
Quiz
Historical Background
Noam Chomsky introduced the hierarchy in his 1956 paper 'Three Models for the Description of Language' and expanded it in 'On Certain Formal Properties of Grammars' (1959), originally motivated by trying to formally characterize the syntax of natural human languages. The correspondence between each grammar type and an equivalent automaton (finite automata for Type 3, pushdown automata for Type 2, linear-bounded automata for Type 1, and Turing machines for Type 0) was established over the following years by Chomsky, John Myhill, and others, cementing the hierarchy as a foundational structure in both linguistics and computer science.
- 1956
Noam Chomsky publishes 'Three Models for the Description of Language', introducing the grammar hierarchy
Noam Chomsky
- 1959
Chomsky formalizes the four grammar types in 'On Certain Formal Properties of Grammars'
Noam Chomsky
- 1960s
The equivalences between each grammar type and its corresponding automaton model are established
Summary
- The Chomsky hierarchy has four nested classes: regular ⊊ context-free ⊊ context-sensitive ⊊ recursively enumerable (Type 3, 2, 1, 0).
- Each class matches a machine model: finite automata, pushdown automata, linear-bounded automata, and Turing machines, respectively.
- The containments are strict — e.g. {aⁿbⁿ} is context-free but not regular, and {aⁿbⁿcⁿ} is context-sensitive but not context-free.
- Real programming languages sit mostly at the context-free level for efficient parsing, pushing context-sensitive checks into a separate semantic-analysis phase.
Mathematics