Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Chomsky hierarchy
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Hierarchy of classes of formal grammars}} [[Image:Chomsky-hierarchy.svg|thumb|right|200px|alt=The Chomsky hierarchy|Set inclusions described by the Chomsky hierarchy]] The '''Chomsky hierarchy''' in the fields of [[formal language|formal language theory]], [[computer science]], and [[linguistics]], is a [[Hierarchy#Containment hierarchy|containment hierarchy]] of classes of [[formal grammar]]s. A formal grammar describes how to form strings from a formal language's [[alphabet (formal languages)|alphabet]] that are valid according to the language's syntax. The linguist [[Noam Chomsky]] theorized that four different classes of formal grammars existed that could generate increasingly complex languages. Each class can also completely generate the language of all inferior classes (set inclusive). == History == The general idea of a hierarchy of grammars was first described by Noam Chomsky in "Three models for the description of language" during the formalization of [[transformational-generative grammar]] (TGG).{{sfn|Chomsky|1956}} [[Marcel-Paul Schützenberger]] also played a role in the development of the theory of [[formal language]]s; the paper "The algebraic theory of context free languages"{{Sfn|Chomsky|Schützenberger|1963}} describes the modern hierarchy, including context-free grammars.<ref name=Allott>{{cite book |last1=Allott |first1=Nicholas |last2=Lohndal |first2=Terje |last3=Rey |first3=Georges |chapter=Synoptic Introduction |title=A Companion to Chomsky |date=27 April 2021 |pages=1–17 |doi=10.1002/9781119598732.ch1 |isbn=9781119598701 |s2cid=241301126 |url=https://www.researchgate.net/publication/351812216}}</ref> Independently, alongside linguists, mathematicians were developing models of computation (via [[automata]]). Parsing a sentence in a language is similar to computation, and the grammars described by Chomsky proved to both resemble and be equivalent in computational power to various machine models.<ref>{{cite book | last=Kozen | first=Dexter C. | title=Automata and computability | publisher=Springer | series=Undergraduate Texts in Computer Science | year=2007 | isbn=978-0-387-94907-9 | url=https://books.google.com/books?id=8lKyxS8_CNoC |pages=3–4}}</ref> == The hierarchy == The following table summarizes each of Chomsky's four types of grammars, the class of language it generates, the type of automaton that recognizes it, and the form its rules must have. The classes are defined by the constraints on the productions rules. {| class="wikitable sortable" |- ! Grammar ! Languages ! Recognizing automaton ! Production rules (constraints){{efn|1= Meaning of symbols: * <math>\text{a}</math> = [[Terminal symbol|terminal]] * <math>A</math>, <math>B</math> = [[Nonterminal symbol|non-terminal]] * <math>\alpha</math>, <math>\beta</math>, <math>\gamma</math> = string of terminals and/or non-terminals }} ! Examples<ref>{{cite web |first1=H. |last1=Geuvers |first2=J. |last2=Rot |date=2016 |title=Applications, Chomsky hierarchy, and Recap |work=Regular Languages |url=https://www.cs.ru.nl/~herman/onderwijs/2016TnA/lecture7.pdf |archive-url=https://web.archive.org/web/20181119092124/http://www.cs.ru.nl/~herman/onderwijs/2016TnA/lecture7.pdf |archive-date=2018-11-19 |url-status=live }}</ref><ref>{{cite book | last=Sudkamp | first=Thomas A. | date=1997 | orig-year=1988 | title=Languages and machines: An Introduction to the Theory of Computer Science | publisher=Addison Wesley Longman | publication-place=Reading, Massachusetts, USA | isbn=978-0-201-82136-9 | page=310}}</ref> |- | [[regular grammar|Type-3]] | [[regular language|Regular]] | [[Finite-state automaton]] | <math>A \rightarrow \text{a}</math><br/><math>A \rightarrow \text{a}B</math> (right regular)<br/>or<br/><math>A \rightarrow \text{a}</math><br/><math>A \rightarrow B\text{a}</math> (left regular) | <math>L = \{a^n \mid n > 0\}</math> |- | [[context-free grammar|Type-2]] | [[context-free language|Context-free]] | Non-deterministic [[pushdown automaton]] |<math>A \rightarrow \alpha</math> | <math>L = \{a^nb^n \mid n > 0\}</math> |- | [[context-sensitive grammar|Type-1]] | [[context-sensitive language|Context-sensitive]] | [[Linear bounded automaton|Linear-bounded non-deterministic Turing machine]] | <math>\alpha A \beta \rightarrow \alpha \gamma \beta</math> | <math>L = \{a^nb^nc^n \mid n > 0\}</math> |- | [[Unrestricted grammar|Type-0]] | [[recursively enumerable language|Recursively enumerable]] | [[Turing machine]] | <math>\gamma \rightarrow \alpha</math> (<math>\gamma</math> non-empty) | <math>L = \{w \mid w</math> describes a terminating Turing machine <math>\}</math> |- |} {{noteslist}} Note that the set of grammars corresponding to [[recursive language]]s is not a member of this hierarchy; these would be properly between Type-0 and Type-1. Every regular language is context-free, every context-free language is context-sensitive, every context-sensitive language is recursive and every recursive language is recursively enumerable. These are all proper inclusions, meaning that there exist recursively enumerable languages that are not context-sensitive, context-sensitive languages that are not context-free and context-free languages that are not regular.<ref>{{cite book |last=Chomsky |first=Noam |editor1-last=Luce |editor1-first=R. Duncan |editor2-last=Bush |editor2-first=Robert R. |editor3-last=Galanter |editor3-first=Eugene |year=1963 |title=Handbook of Mathematical Psychology |volume=II |chapter=Chapter 12: Formal Properties of Grammars |publisher=John Wiley and Sons, Inc. |pages=323–418}}</ref> ===Regular (Type-3) grammars=== {{main|Regular grammar}} Type-3 grammars generate the [[regular language]]s. Such a grammar restricts its rules to a single nonterminal on the left-hand side and a right-hand side consisting of a single terminal, possibly followed by a single nonterminal, in which case the grammar is ''right regular''. Alternatively, all the rules can have their right-hand sides consist of a single terminal, possibly ''preceded'' by a single nonterminal (''left regular''). These generate the same languages. However, if left-regular rules and right-regular rules are combined, the language need no longer be regular. The rule <math>S \rightarrow \varepsilon</math> is also allowed here if <math>S</math> does not appear on the right side of any rule. These languages are exactly all languages that can be decided by a [[finite-state automaton]]. Additionally, this family of formal languages can be obtained by [[regular expression]]s. Regular languages are commonly used to define search patterns and the lexical structure of programming languages. For example, the regular language <math>L = \{a^n \mid n > 0\}</math> is generated by the Type-3 grammar <math>G = (\{S\}, \{a, b\}, P, S)</math> with the productions <math>P</math> being the following. :{{math|''S'' → ''aS''}} :{{math|''S'' → ''a''}} ===Context-free (Type-2) grammars=== {{main|Context-free grammar}} Type-2 grammars generate the [[context-free language]]s. These are defined by rules of the form <math>A \rightarrow \alpha</math> with <math>A</math> being a nonterminal and <math>\alpha</math> being a string of terminals and/or nonterminals. These languages are exactly all languages that can be recognized by a non-deterministic [[pushdown automaton]]. Context-free languages—or rather its subset of [[deterministic context-free language|deterministic context-free languages]]—are the theoretical basis for the phrase structure of most [[programming language]]s, though their syntax also includes context-sensitive [[Name resolution (programming languages)|name resolution]] due to declarations and [[Scope (computer science)|scope]]. Often a subset of grammars is used to make parsing easier, such as by an [[LL parser]]. For example, the context-free language <math>L = \{a^nb^n \mid n > 0\}</math> is generated by the Type-2 grammar <math>G = (\{S\}, \{a, b\}, P, S)</math> with the productions <math>P</math> being the following. :{{math|''S'' → ''aSb''}} :{{math|''S'' → ''ab''}} The language is context-free but not regular (by the [[pumping lemma for regular languages]]). ===Context-sensitive (Type-1) grammars=== {{main|Context-sensitive grammar}} Type-1 grammars generate [[context-sensitive language]]s. These grammars have rules of the form <math>\alpha A\beta \rightarrow \alpha\gamma\beta</math> with <math>A</math> a nonterminal and <math>\alpha</math>, <math>\beta</math> and <math>\gamma</math> strings of terminals and/or nonterminals. The strings <math>\alpha</math> and <math>\beta</math> may be empty, but <math>\gamma</math> must be nonempty. The rule <math>S \rightarrow \epsilon</math> is allowed if <math>S</math> does not appear on the right side of any rule. The languages described by these grammars are exactly all languages that can be recognized by a [[linear bounded automaton]] (a nondeterministic Turing machine whose tape is bounded by a constant times the length of the input.) For example, the context-sensitive language <math>L = \{a^nb^nc^n \mid n > 0\}</math> is generated by the Type-1 grammar <math>G = (\{S,A,B,C,W,Z\}, \{a, b, c\}, P, S)</math> with the productions <math>P</math> being the following. :{{math|''S'' → ''aBC''}} :{{math|''S'' → ''aSBC''}} :{{math|''CB'' → ''CZ''}} :{{math|''CZ'' → ''WZ''}} :{{math|''WZ'' → ''WC''}} :{{math|''WC'' → ''BC''}} :{{math|''aB'' → ''ab''}} :{{math|''bB'' → ''bb''}} :{{math|''bC'' → ''bc''}} :{{math|''cC'' → ''cc''}} The language is context-sensitive but not context-free (by the [[pumping lemma for context-free languages]]). A proof that this grammar generates <math>L = \{a^nb^nc^n \mid n > 0\}</math> is sketched in the article on [[Context-sensitive grammar#anbncn|Context-sensitive grammars]]. ===Recursively enumerable (Type-0) grammars=== {{main|Unrestricted grammar}} Type-0 grammars include all formal grammars. There are no constraints on the productions rules. They generate exactly all languages that can be recognized by a [[Turing machine]], thus any language that is possible to be generated can be generated by a Type-0 grammar.<ref name=Sipser-1st /> These languages are also known as the [[recursively enumerable language|''recursively enumerable'']] or ''Turing-recognizable'' languages.<ref name=Sipser-1st>{{cite book |last=Sipser |first=Michael |author-link=Michael Sipser |year=1997 |title=Introduction to the Theory of Computation |edition=1st |publisher=Cengage Learning |isbn=0-534-94728-X |page=[https://archive.org/details/introductiontoth00sips/page/130 130] |url=https://archive.org/details/introductiontoth00sips/page/130 |url-access=registration |quote=The Church-Turing Thesis }}</ref> Note that this is different from the [[recursive language]]s, which can be ''decided'' by an [[machine that always halts|always-halting Turing machine]]. ==See also== * [[Chomsky normal form]] == Citations == {{Reflist}} == References == {{refbegin}} *{{cite journal |last=Chomsky |first=Noam |author-link=Noam Chomsky |date=1956 |title=Three models for the description of language |doi=10.1109/TIT.1956.1056813 |journal=IRE Transactions on Information Theory |volume=2 |issue=3 |pages=113–124 |s2cid=19519474 |url=https://chomsky.info/wp-content/uploads/195609-.pdf |archive-url=https://web.archive.org/web/20160307035549/https://chomsky.info/wp-content/uploads/195609-.pdf |archive-date=2016-03-07 |url-status=live }} *{{cite journal|last=Chomsky|first=Noam|author-link=Noam Chomsky|date=1959|title=On certain formal properties of grammars|volume=2|journal=Information and Control|doi=10.1016/S0019-9958(59)90362-6|via=|issue=2|pages=137–167|url=https://www.sciencedirect.com/science/article/pii/S0019995859903626/pdf?md5=9d466f851651bd592afa5ee561b7a0b0&pid=1-s2.0-S0019995859903626-main.pdf|doi-access=free}} *{{cite book|last1=Chomsky|first1=Noam|author-link1=Noam Chomsky|last2=Schützenberger|first2=Marcel P.|isbn=|editor1-last=Braffort|editor1-first=P.|editor2-last=Hirschberg|editor2-first=D.|date=1963|title=Computer Programming and Formal Systems|chapter=The algebraic theory of context free languages|publisher=North Holland|location=Amsterdam|pages=118–161|url=http://www-igm.univ-mlv.fr/~berstel/Mps/Travaux/A/1963-7ChomskyAlgebraic.pdf |archive-url=https://web.archive.org/web/20110613164145/http://www-igm.univ-mlv.fr/~berstel/Mps/Travaux/A/1963-7ChomskyAlgebraic.pdf |archive-date=2011-06-13 |url-status=live}} {{refend}} {{Formal languages and grammars}} {{Noam Chomsky}} {{Authority control}} [[Category:1956 in computing]] [[Category:Formal languages]] [[Category:Generative linguistics]] [[Category:Noam Chomsky|Hierarchy, Chomsky]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Authority control
(
edit
)
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:Efn
(
edit
)
Template:Formal languages and grammars
(
edit
)
Template:Main
(
edit
)
Template:Math
(
edit
)
Template:Noam Chomsky
(
edit
)
Template:Noteslist
(
edit
)
Template:Refbegin
(
edit
)
Template:Refend
(
edit
)
Template:Reflist
(
edit
)
Template:Sfn
(
edit
)
Template:Short description
(
edit
)