<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.tachyony.co.uk/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=129.101.71.84</id>
	<title>Wikipedia - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.tachyony.co.uk/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=129.101.71.84"/>
	<link rel="alternate" type="text/html" href="https://wiki.tachyony.co.uk/wiki/Special:Contributions/129.101.71.84"/>
	<updated>2026-07-08T05:37:04Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://wiki.tachyony.co.uk/w/index.php?title=Context-sensitive_grammar&amp;diff=16080</id>
		<title>Context-sensitive grammar</title>
		<link rel="alternate" type="text/html" href="https://wiki.tachyony.co.uk/w/index.php?title=Context-sensitive_grammar&amp;diff=16080"/>
		<updated>2024-10-28T19:16:31Z</updated>

		<summary type="html">&lt;p&gt;129.101.71.84: moved production 0 to top of list&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Short description|Type of a formal grammar}}&lt;br /&gt;
A &#039;&#039;&#039;context-sensitive grammar&#039;&#039;&#039; (&#039;&#039;&#039;CSG&#039;&#039;&#039;) is a [[formal grammar]] in which the left-hand sides and right-hand sides of any [[Production (computer science)|production rules]] may be surrounded by a context of [[terminal symbol|terminal]] and [[nonterminal symbol]]s. Context-sensitive grammars are more general than [[context-free grammar]]s, in the sense that there are languages that can be described by a CSG but not by a context-free grammar. Context-sensitive grammars are less general (in the same sense) than [[unrestricted grammar]]s. Thus, CSGs are positioned between context-free and unrestricted grammars in the [[Chomsky hierarchy]].&amp;lt;ref&amp;gt;(Hopcroft, Ullman, 1979); Sect.9.4, p.227&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A [[formal language]] that can be described by a context-sensitive grammar, or, equivalently, by a [[noncontracting grammar]] or a [[linear bounded automaton]], is called a [[context-sensitive language]]. Some textbooks actually define CSGs as non-contracting,&amp;lt;ref name=&amp;quot;Linz2011&amp;quot;&amp;gt;{{cite book|first=Peter|last=Linz|title=An Introduction to Formal Languages and Automata|url=https://books.google.com/books?id=hsxDiWvVdBcC&amp;amp;pg=PA291|year=2011|publisher=Jones &amp;amp; Bartlett Publishers|isbn=978-1-4496-1552-9|page=291}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;Meduna2000&amp;quot;&amp;gt;{{cite book|first=Alexander|last=Meduna|author-link=Alexander Meduna|title=Automata and Languages: Theory and Applications|url=https://books.google.com/books?id=s7gEErax71cC&amp;amp;pg=PA730|year=2000|publisher=Springer Science &amp;amp; Business Media|isbn=978-1-85233-074-3|page=730}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;DavisSigal1994&amp;quot;&amp;gt;{{cite book|first1=Martin|last1=Davis|author-link1=Martin Davis (mathematician)|first2=Ron|last2=Sigal|first3=Elaine J.|last3=Weyuker|author-link3=Elaine Weyuker|title=Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science|url=https://books.google.com/books?id=dSHIIx0uGx0C&amp;amp;pg=PA189|year=1994|publisher=Morgan Kaufmann|isbn=978-0-08-050246-5|page=189|edition=2nd}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{cite book|last=Martin|first=John C.|title=Introduction to Languages and the Theory of Computation|year=2010|publisher=McGraw-Hill|location=New York, NY|isbn=9780073191461|edition=4th|page=277}}&amp;lt;/ref&amp;gt; although this is not how [[Noam Chomsky]] defined them in 1959.&amp;lt;ref name=&amp;quot;Levelt2008&amp;quot;&amp;gt;{{cite book|first=Willem J. M.|last=Levelt|author-link=Willem Levelt|title=An Introduction to the Theory of Formal Languages and Automata|url=https://books.google.com/books?id=tFvtwGYNe7kC&amp;amp;pg=PA26|year=2008|publisher=John Benjamins Publishing|isbn=978-90-272-3250-2|page=26}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;DavisSigal1994b&amp;quot;&amp;gt;{{cite book|first1=Martin|last1=Davis|author-link1=Martin Davis (mathematician)|first2=Ron |last2=Sigal|first3=Elaine J.|last3=Weyuker|author-link3=Elaine Weyuker|title=Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science|url=https://books.google.com/books?id=dSHIIx0uGx0C&amp;amp;pg=PA330|year=1994|publisher=Morgan Kaufmann|isbn=978-0-08-050246-5|pages=330–331|edition=2nd}}&amp;lt;/ref&amp;gt; This choice of definition makes no difference in terms of the languages generated (i.e. the two definitions are [[weak equivalence (formal languages)|weakly equivalent]]), but it does make a difference in terms of what grammars are structurally considered context-sensitive; the latter issue was analyzed by Chomsky in 1963.&amp;lt;ref&amp;gt;{{cite book |last=Chomsky |first=N. |author-link=Noam Chomsky|year=1963|chapter=Formal properties of grammar|title=Handbook of Mathematical Psychology|editor1-first=R. D.|editor1-last=Luce|editor2-first=R. R.|editor2-last=Bush|editor3-first=E.|editor3-last=Galanter|location=New York|publisher=Wiley|pages=360–363|chapter-url=https://archive.org/details/handbookofmathem017893mbp}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;Levelt2008-126&amp;quot;&amp;gt;{{cite book|first=Willem J. M.|last=Levelt|author-link=Willem Levelt|title=An Introduction to the Theory of Formal Languages and Automata|url=https://books.google.com/books?id=tFvtwGYNe7kC&amp;amp;pg=PA125|year=2008|publisher=John Benjamins Publishing|isbn=978-90-272-3250-2|pages=125–126}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chomsky introduced context-sensitive grammars as a way to describe the syntax of [[natural language]] where it is often the case that a word may or may not be appropriate in a certain place depending on the context. [[Walter Savitch]] has criticized the terminology &amp;quot;context-sensitive&amp;quot; as misleading and proposed &amp;quot;non-erasing&amp;quot; as better explaining the distinction between a CSG and an [[unrestricted grammar]].&amp;lt;ref name=&amp;quot;Vide1999&amp;quot;&amp;gt;{{cite book|editor=Carlos Martín Vide|title=Issues in Mathematical Linguistics: Workshop on Mathematical Linguistics, State College, Pa., April 1998|url=https://books.google.com/books?id=BW2QNSvH2CoC&amp;amp;pg=PA186|year=1999|publisher=John Benjamins Publishing|isbn=90-272-1556-1|pages=186–187}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although it is well known that certain features of languages (e.g. [[cross-serial dependency]]) are not context-free, it is an [[open problem|open question]] how much of CSGs&#039; expressive power is needed to capture the context sensitivity found in natural languages. Subsequent research in this area has focused on the more computationally tractable [[mildly context-sensitive language]]s.{{citation needed|date=March 2018}} The syntaxes of some [[visual programming language]]s can be described by context-sensitive [[graph grammar]]s.&amp;lt;ref&amp;gt;Zhang, Da-Qian, Kang Zhang, and Jiannong Cao. &amp;quot;[https://web.archive.org/web/20180323220143/https://pdfs.semanticscholar.org/5d3d/217d73e0f6bbeefa3749c16fbc7b2e00ec0b.pdf A context-sensitive graph grammar formalism for the specification of visual languages].&amp;quot; [[The Computer Journal]] 44.3 (2001): 186–200.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Formal definition==&lt;br /&gt;
&lt;br /&gt;
=== Formal grammar ===&lt;br /&gt;
Let us notate a [[formal grammar]] as &amp;lt;math&amp;gt;G = (N, \Sigma, P, S)&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; a set of nonterminal symbols, &amp;lt;math&amp;gt;\Sigma&amp;lt;/math&amp;gt; a set of terminal symbols, &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; a set of production rules, and &amp;lt;math&amp;gt;S \in N&amp;lt;/math&amp;gt; the start symbol.&lt;br /&gt;
&lt;br /&gt;
A string &amp;lt;math&amp;gt;u \in (N \cup \Sigma)^*&amp;lt;/math&amp;gt; &#039;&#039;directly yields&#039;&#039;, or &#039;&#039;directly derives to&#039;&#039;, a string &amp;lt;math&amp;gt;v \in (N \cup \Sigma)^*&amp;lt;/math&amp;gt;, denoted as &amp;lt;math&amp;gt;u \Rightarrow v&amp;lt;/math&amp;gt;, if &#039;&#039;v&#039;&#039; can be obtained from &#039;&#039;u&#039;&#039; by an application of some production rule in &#039;&#039;P&#039;&#039;, that is, if &amp;lt;math&amp;gt;u = \gamma L \delta&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v = \gamma R \delta&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;(L \to R) \in P&amp;lt;/math&amp;gt; is a production rule, and &amp;lt;math&amp;gt;\gamma, \delta \in (N \cup \Sigma)^*&amp;lt;/math&amp;gt; is the unaffected left and right part of the string, respectively.&lt;br /&gt;
More generally, &#039;&#039;u&#039;&#039; is said to &#039;&#039;yield&#039;&#039;, or &#039;&#039;derive to&#039;&#039;, &#039;&#039;v&#039;&#039;, denoted as &amp;lt;math&amp;gt;u \Rightarrow^* v&amp;lt;/math&amp;gt;, if &#039;&#039;v&#039;&#039; can be obtained from &#039;&#039;u&#039;&#039; by repeated application of production rules, that is, if &amp;lt;math&amp;gt;u = u_0 \Rightarrow ... \Rightarrow u_n = v&amp;lt;/math&amp;gt; for some &#039;&#039;n&#039;&#039; ≥ 0 and some strings &amp;lt;math&amp;gt;u_1, ..., u_{n-1} \in (N \cup \Sigma)^*&amp;lt;/math&amp;gt;. In other words, the relation &amp;lt;math&amp;gt;\Rightarrow^*&amp;lt;/math&amp;gt; is the [[reflexive transitive closure]] of the relation &amp;lt;math&amp;gt;\Rightarrow&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;language&#039;&#039;&#039; of the grammar &#039;&#039;G&#039;&#039; is the set of all terminal-symbol strings derivable from its start symbol, formally: &amp;lt;math&amp;gt;L(G) = \{ w \in \Sigma^* \mid S \Rightarrow^* w \}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Derivations that do not end in a string composed of terminal symbols only are possible, but do not contribute to &#039;&#039;L&#039;&#039;(&#039;&#039;G&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
=== Context-sensitive grammar ===&lt;br /&gt;
A formal grammar is &#039;&#039;&#039;context-sensitive&#039;&#039;&#039; if each rule in &#039;&#039;P&#039;&#039; is either of the form &amp;lt;math&amp;gt;S \to \varepsilon&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;\varepsilon&amp;lt;/math&amp;gt; is the [[empty string]], or of the form&lt;br /&gt;
: α&#039;&#039;A&#039;&#039;β → αγβ&lt;br /&gt;
with &#039;&#039;A&#039;&#039; ∈ &#039;&#039;N&#039;&#039;,&amp;lt;ref group=&amp;quot;note&amp;quot;&amp;gt;i.e., &#039;&#039;A&#039;&#039; a single [[nonterminal]]&amp;lt;/ref&amp;gt; &amp;lt;math&amp;gt;\alpha, \beta\in (N \cup \Sigma \setminus\{S\})^*&amp;lt;/math&amp;gt;,&amp;lt;ref group=&amp;quot;note&amp;quot;&amp;gt;i.e., α and β strings of nonterminals (except for the start symbol) and [[Terminal symbol|terminals]]&amp;lt;/ref&amp;gt; and &amp;lt;math&amp;gt;\gamma\in (N \cup \Sigma \setminus\{S\})^+&amp;lt;/math&amp;gt;.&amp;lt;ref group=&amp;quot;note&amp;quot;&amp;gt;i.e., γ is a nonempty string of nonterminals (except for the start symbol) and terminals&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The name &#039;&#039;context-sensitive&#039;&#039; is explained by the α and β that form the context of &#039;&#039;A&#039;&#039; and determine whether &#039;&#039;A&#039;&#039; can be replaced with γ or not.&lt;br /&gt;
By contrast, in a [[context-free grammar]], no context is present: the left hand side of every production rule is just a nonterminal.&lt;br /&gt;
&lt;br /&gt;
The string γ is not allowed to be empty.  Without this restriction, the resulting grammars become equal in power to [[unrestricted grammar]]s.&amp;lt;ref name=&amp;quot;Vide1999&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== (Weakly) equivalent definitions ===&lt;br /&gt;
A [[noncontracting grammar]] is a grammar in which for any production rule, of the form &#039;&#039;u&#039;&#039; → &#039;&#039;v&#039;&#039;, the length of &#039;&#039;u&#039;&#039; is less than or equal to the length of &#039;&#039;v&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Every context-sensitive grammar is noncontracting, while every noncontracting grammar can be converted into an equivalent context-sensitive grammar; the two classes are [[weak equivalence (formal languages)|weakly equivalent]].&amp;lt;ref&amp;gt;{{cite book |last1=Hopcroft |first1=John E. |url=https://archive.org/details/introductiontoau00hopc |title=Introduction to Automata Theory, Languages, and Computation |last2=Ullman |first2=Jeffrey D. |publisher=Addison-Wesley |year=1979 |isbn=9780201029888 |author-link1=John Hopcroft |author-link2=Jeffrey Ullman |url-access=registration}}; p.&amp;amp;nbsp;223–224; Exercise 9, p.&amp;amp;nbsp;230. In the 2003 edition, the chapter on CSGs has been omitted.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some authors use the term &#039;&#039;context-sensitive grammar&#039;&#039; to refer to noncontracting grammars in general.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;left-context&#039;&#039;&#039;- and &#039;&#039;&#039;right-context&#039;&#039;&#039;-sensitive grammars are defined by restricting the rules to just the form α&#039;&#039;A&#039;&#039; → αγ and to just &#039;&#039;A&#039;&#039;β → γβ, respectively. The languages generated by these grammars are also the full class of context-sensitive languages.&amp;lt;ref name=&amp;quot;Hazewinkel1989&amp;quot;&amp;gt;{{cite book |last=Hazewinkel |first=Michiel |url=https://books.google.com/books?id=s9F71NJxwzoC&amp;amp;pg=PA297 |title=Encyclopaedia of Mathematics |publisher=Springer Science &amp;amp; Business Media |year=1989 |isbn=978-1-55608-003-6 |volume=4 |page=297 |author-link=Michiel Hazewinkel}} also at https://www.encyclopediaofmath.org/index.php/Grammar,_context-sensitive&amp;lt;/ref&amp;gt; The equivalence was established by [[Penttonen normal form]].&amp;lt;ref name=&amp;quot;ItoKobayashi2010&amp;quot;&amp;gt;{{cite book |last1=Ito |first1=Masami |url=https://books.google.com/books?id=xuaR2bJq0rcC&amp;amp;pg=PA183 |title=Automata, Formal Languages and Algebraic Systems: Proceedings of AFLAS 2008, Kyoto, Japan, 20–22 September 2008 |last2=Kobayashi |first2=Yūji |last3=Shoji |first3=Kunitaka |publisher=World Scientific |year=2010 |isbn=978-981-4317-60-3 |page=183}} citing {{Cite journal |last1=Penttonen |first1=Martti |date=Aug 1974 |title=One-sided and two-sided context in formal grammars |journal=[[Information and Control]] |volume=25 |issue=4 |pages=371–392 |doi=10.1016/S0019-9958(74)91049-3 |doi-access=free}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
=== &#039;&#039;a&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;b&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;c&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;&#039;&#039; ===&lt;br /&gt;
The following context-sensitive grammar, with start symbol &#039;&#039;S&#039;&#039;, generates the canonical non-[[context-free language]] { &#039;&#039;a&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;b&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;c&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;&#039;&#039; | &#039;&#039;n&#039;&#039; ≥ 1 } :{{cn|date=January 2022}}&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|- &lt;br /&gt;
| 1. &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; || || &#039;&#039;S&#039;&#039; &amp;amp;nbsp; &amp;amp;nbsp; || → &amp;amp;nbsp; &amp;amp;nbsp; || &#039;&#039;a&#039;&#039; || &#039;&#039;B&#039;&#039; || &#039;&#039;C&#039;&#039; &lt;br /&gt;
|-&lt;br /&gt;
| 2. || || &#039;&#039;S&#039;&#039; || → || &#039;&#039;a&#039;&#039; || &#039;&#039;S&#039;&#039; || &#039;&#039;B&#039;&#039; || &#039;&#039;C&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 3. || &#039;&#039;C&#039;&#039; || &#039;&#039;B&#039;&#039; || → || &#039;&#039;C&#039;&#039; || &#039;&#039;Z&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 4. || &#039;&#039;C&#039;&#039; || &#039;&#039;Z&#039;&#039; || → || &#039;&#039;W&#039;&#039; || &#039;&#039;Z&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 5. || &#039;&#039;W&#039;&#039; || &#039;&#039;Z&#039;&#039; || → || &#039;&#039;W&#039;&#039; || &#039;&#039;C&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 6. || &#039;&#039;W&#039;&#039; || &#039;&#039;C&#039;&#039; || → || &#039;&#039;B&#039;&#039; || &#039;&#039;C&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 7. || &#039;&#039;a&#039;&#039; || &#039;&#039;B&#039;&#039; || → || &#039;&#039;a&#039;&#039; || &#039;&#039;b&#039;&#039; &lt;br /&gt;
|-&lt;br /&gt;
| 8. || &#039;&#039;b&#039;&#039; || &#039;&#039;B&#039;&#039; || → || &#039;&#039;b&#039;&#039; || &#039;&#039;b&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| 9. || &#039;&#039;b&#039;&#039; || &#039;&#039;C&#039;&#039; || → || &#039;&#039;b&#039;&#039; || &#039;&#039;c&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|10. || &#039;&#039;c&#039;&#039; || &#039;&#039;C&#039;&#039; || → || &#039;&#039;c&#039;&#039; || &#039;&#039;c&#039;&#039;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;!---&lt;br /&gt;
# &#039;&#039;S&#039;&#039; → &#039;&#039;aSBC&#039;&#039;&lt;br /&gt;
# &#039;&#039;S&#039;&#039; → &#039;&#039;aBC&#039;&#039;&lt;br /&gt;
# &#039;&#039;CB&#039;&#039; → &#039;&#039;HB&#039;&#039;&lt;br /&gt;
# &#039;&#039;HB&#039;&#039; → &#039;&#039;HC&#039;&#039;&lt;br /&gt;
# &#039;&#039;HC&#039;&#039; → &#039;&#039;BC&#039;&#039;&lt;br /&gt;
# &#039;&#039;aB&#039;&#039; → &#039;&#039;ab&#039;&#039;&lt;br /&gt;
# &#039;&#039;bB&#039;&#039; → &#039;&#039;bb&#039;&#039;&lt;br /&gt;
# &#039;&#039;bC&#039;&#039; → &#039;&#039;bc&#039;&#039;&lt;br /&gt;
# &#039;&#039;cC&#039;&#039; → &#039;&#039;cc&#039;&#039;&lt;br /&gt;
---&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rules 1 and 2 allow for blowing-up &#039;&#039;S&#039;&#039; to &#039;&#039;a&#039;&#039;&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sup&amp;gt;&#039;&#039;BC&#039;&#039;(&#039;&#039;BC&#039;&#039;)&amp;lt;sup&amp;gt;&#039;&#039;n&#039;&#039;−1&amp;lt;/sup&amp;gt;; rules 3 to 6 allow for successively exchanging each &#039;&#039;CB&#039;&#039; to &#039;&#039;BC&#039;&#039; ([[Revesz&#039; trick|four rules]] are needed for that since a rule &#039;&#039;CB&#039;&#039; → &#039;&#039;BC&#039;&#039; wouldn&#039;t fit into the scheme α&#039;&#039;A&#039;&#039;β → αγβ); rules 7–10 allow replacing a non-terminal &#039;&#039;B&#039;&#039; or &#039;&#039;C&#039;&#039; with its corresponding terminal &#039;&#039;b&#039;&#039; or &#039;&#039;c&#039;&#039;, respectively, provided it is in the right place.&lt;br /&gt;
A generation chain for &#039;&#039;{{not a typo|aaabbbccc}}&#039;&#039; is:&lt;br /&gt;
: &#039;&#039;S&#039;&#039;&lt;br /&gt;
: →&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;&#039;aSBC&#039;&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;a&#039;&#039;&#039;aSBC&#039;&#039;&#039;BC&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aa&#039;&#039;&#039;aBC&#039;&#039;&#039;BCBC&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaaB&#039;&#039;&#039;CZ&#039;&#039;&#039;CBC&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;4&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaaB&#039;&#039;&#039;WZ&#039;&#039;&#039;CBC&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;5&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaaB&#039;&#039;&#039;WC&#039;&#039;&#039;CBC&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;6&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaaB&#039;&#039;&#039;BC&#039;&#039;&#039;CBC&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaaBBC&#039;&#039;&#039;CZ&#039;&#039;&#039;C&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;4&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaaBBC&#039;&#039;&#039;WZ&#039;&#039;&#039;C&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;5&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaaBBC&#039;&#039;&#039;WC&#039;&#039;&#039;C&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;6&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaaBBC&#039;&#039;&#039;BC&#039;&#039;&#039;C&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaaBB&#039;&#039;&#039;CZ&#039;&#039;&#039;CC&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;4&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaaBB&#039;&#039;&#039;WZ&#039;&#039;&#039;CC&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;5&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaaBB&#039;&#039;&#039;WC&#039;&#039;&#039;CC&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;6&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaaBB&#039;&#039;&#039;BC&#039;&#039;&#039;CC&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;7&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aa&#039;&#039;&#039;ab&#039;&#039;&#039;BBCCC&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;8&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaa&#039;&#039;&#039;bb&#039;&#039;&#039;BCCC&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;8&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaab&#039;&#039;&#039;bb&#039;&#039;&#039;CCC&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;9&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaabb&#039;&#039;&#039;bc&#039;&#039;&#039;CC&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;10&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaabbb&#039;&#039;&#039;cc&#039;&#039;&#039;C&#039;&#039;}}&lt;br /&gt;
: →&amp;lt;sub&amp;gt;10&amp;lt;/sub&amp;gt; {{not a typo|&#039;&#039;aaabbbc&#039;&#039;&#039;cc&#039;&#039;&#039;&#039;&#039;}}&lt;br /&gt;
:&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;a&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;b&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;c&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;d&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;&#039;&#039;, etc. ===&lt;br /&gt;
More complicated grammars can be used to parse { &#039;&#039;a&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;b&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;c&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;d&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;&#039;&#039; | &#039;&#039;n&#039;&#039; ≥ 1 }, and other languages with even more letters. Here we show a simpler approach using non-contracting grammars:{{cn|date=January 2022}}&lt;br /&gt;
Start with a kernel of regular productions generating the sentential forms&lt;br /&gt;
&amp;lt;math&amp;gt;(ABCD)^{n}abcd&amp;lt;/math&amp;gt; and then include the non contracting productions&lt;br /&gt;
&amp;lt;math&amp;gt;p_{Da} : Da\rightarrow aD&amp;lt;/math&amp;gt;,&lt;br /&gt;
&amp;lt;math&amp;gt;p_{Db} : Db\rightarrow bD&amp;lt;/math&amp;gt;,&lt;br /&gt;
&amp;lt;math&amp;gt;p_{Dc} : Dc\rightarrow cD&amp;lt;/math&amp;gt;,&lt;br /&gt;
&amp;lt;math&amp;gt;p_{Dd} : Dd\rightarrow dd&amp;lt;/math&amp;gt;,&lt;br /&gt;
&amp;lt;math&amp;gt;p_{Ca} : Ca\rightarrow aC&amp;lt;/math&amp;gt;,&lt;br /&gt;
&amp;lt;math&amp;gt;p_{Cb} : Cb\rightarrow bC&amp;lt;/math&amp;gt;,&lt;br /&gt;
&amp;lt;math&amp;gt;p_{Cc} : Cc\rightarrow cc&amp;lt;/math&amp;gt;,&lt;br /&gt;
&amp;lt;math&amp;gt;p_{Ba} : Ba\rightarrow aB&amp;lt;/math&amp;gt;,&lt;br /&gt;
&amp;lt;math&amp;gt;p_{Bb} : Bb\rightarrow bb&amp;lt;/math&amp;gt;,&lt;br /&gt;
&amp;lt;math&amp;gt;p_{Aa} : Aa\rightarrow aa&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;a&amp;lt;sup&amp;gt;m&amp;lt;/sup&amp;gt;b&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;c&amp;lt;sup&amp;gt;m&amp;lt;/sup&amp;gt;d&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;&#039;&#039; ===&lt;br /&gt;
A non contracting grammar (for which there is an equivalent CSG) for the language &amp;lt;math&amp;gt;L_{Cross} = \{ a^mb^nc^{m}d^{n} \mid m \ge 1, n \ge 1 \}&amp;lt;/math&amp;gt; is defined by&lt;br /&gt;
:&amp;lt;math&amp;gt;p_0 : S \rightarrow RT&amp;lt;/math&amp;gt;,&lt;br /&gt;
:&amp;lt;math&amp;gt;p_1 : R\rightarrow aRC | aC&amp;lt;/math&amp;gt;,&lt;br /&gt;
:&amp;lt;math&amp;gt;p_3 : T\rightarrow BTd | Bd&amp;lt;/math&amp;gt;,&lt;br /&gt;
:&amp;lt;math&amp;gt;p_5 : CB\rightarrow BC&amp;lt;/math&amp;gt;,&lt;br /&gt;
:&amp;lt;math&amp;gt;p_6 : aB\rightarrow ab&amp;lt;/math&amp;gt;, &lt;br /&gt;
:&amp;lt;math&amp;gt;p_7 : bB\rightarrow bb&amp;lt;/math&amp;gt;, &lt;br /&gt;
:&amp;lt;math&amp;gt;p_8 : Cd\rightarrow cd&amp;lt;/math&amp;gt;, and&lt;br /&gt;
:&amp;lt;math&amp;gt;p_9 : Cc\rightarrow cc&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
With these definitions, a derivation for &amp;lt;math&amp;gt;a^3b^2c^3d^2&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&amp;lt;math&amp;gt;S&lt;br /&gt;
\Rightarrow_{p_0} RT&lt;br /&gt;
\Rightarrow_{p^{2}_{1}p_{2}} a^3C^3T&lt;br /&gt;
\Rightarrow_{p_{3}p_{4}    } a^3C^3B^2d^2&lt;br /&gt;
\Rightarrow_{p^{6}_{5}     } a^3B^2C^3d^2&lt;br /&gt;
\Rightarrow_{p_{6}p_{7}    } a^3b^2C^3d^2&lt;br /&gt;
\Rightarrow_{p_{8}p^{2}_{9}} a^3b^2c^3d^2&lt;br /&gt;
&amp;lt;/math&amp;gt;.{{citation needed|date=November 2018}}&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;a&#039;&#039;&amp;lt;sup&amp;gt;2&amp;lt;sup&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sup&amp;gt;&amp;lt;/sup&amp;gt; ===&lt;br /&gt;
A noncontracting grammar for the language { &#039;&#039;a&#039;&#039;&amp;lt;sup&amp;gt;2&amp;lt;sup&amp;gt;&#039;&#039;i&#039;&#039;&amp;lt;/sup&amp;gt;&amp;lt;/sup&amp;gt; | &#039;&#039;i&#039;&#039; ≥ 1 } is constructed in Example 9.5 (p.&amp;amp;nbsp;224) of (Hopcroft, Ullman, 1979):&amp;lt;ref&amp;gt;They obtained the grammar by systematic transformation of an [[unrestricted grammar]], given in Exm. 9.4, viz.:&lt;br /&gt;
# &amp;lt;math&amp;gt;S\rightarrow ACaB&amp;lt;/math&amp;gt;,&lt;br /&gt;
# &amp;lt;math&amp;gt;Ca\rightarrow aaC&amp;lt;/math&amp;gt;,&lt;br /&gt;
# &amp;lt;math&amp;gt;CB\rightarrow DB&amp;lt;/math&amp;gt;,&lt;br /&gt;
# &amp;lt;math&amp;gt;CB\rightarrow E&amp;lt;/math&amp;gt;,&lt;br /&gt;
# &amp;lt;math&amp;gt;aD\rightarrow Da&amp;lt;/math&amp;gt;,&lt;br /&gt;
# &amp;lt;math&amp;gt;AD\rightarrow AC&amp;lt;/math&amp;gt;,&lt;br /&gt;
# &amp;lt;math&amp;gt;aE\rightarrow Ea&amp;lt;/math&amp;gt;,&lt;br /&gt;
# &amp;lt;math&amp;gt;AE\rightarrow \varepsilon&amp;lt;/math&amp;gt;.&lt;br /&gt;
In the context-sensitive grammar, a string enclosed in square brackets, like &amp;lt;math&amp;gt;[ACaB]&amp;lt;/math&amp;gt;, is considered a single symbol (similar to e.g. &amp;lt;code&amp;gt;&amp;lt;name-part&amp;gt;&amp;lt;/code&amp;gt; in [[Backus–Naur form#Example|Backus–Naur form]]). The symbol names are chosen to resemble the unrestricted grammar. Likewise, rule groups in the context-sensitive grammar are numbered by the unrestricted-grammar rule they originated from.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;math&amp;gt;S\rightarrow [ACaB]&amp;lt;/math&amp;gt;&lt;br /&gt;
# &amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\ [Ca]a\rightarrow aa[Ca] \\ &lt;br /&gt;
\ [Ca][aB]\rightarrow aa[CaB] \\ &lt;br /&gt;
\ [ACa]a\rightarrow [Aa]a[Ca] \\ &lt;br /&gt;
\ [ACa][aB]\rightarrow [Aa]a[CaB] \\ &lt;br /&gt;
\ [ACaB]\rightarrow [Aa][aCB] \\ &lt;br /&gt;
\ [CaB]\rightarrow a[aCB]&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
# &amp;lt;math&amp;gt;[aCB]\rightarrow [aDB]&amp;lt;/math&amp;gt;&lt;br /&gt;
# &amp;lt;math&amp;gt;[aCB]\rightarrow [aE]&amp;lt;/math&amp;gt;&lt;br /&gt;
# &amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\ a[Da]\rightarrow [Da]a \\&lt;br /&gt;
\ [aDB]\rightarrow [DaB] \\ &lt;br /&gt;
\ [Aa][Da]\rightarrow [ADa]a \\ &lt;br /&gt;
\ a[DaB]\rightarrow [Da][aB] \\&lt;br /&gt;
\ [Aa][DaB]\rightarrow [ADa][aB]&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
# &amp;lt;math&amp;gt;[ADa]\rightarrow [ACa]&amp;lt;/math&amp;gt;&lt;br /&gt;
# &amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\ a[Ea]\rightarrow [Ea]a \\&lt;br /&gt;
\ [aE]\rightarrow [Ea] \\&lt;br /&gt;
\ [Aa][Ea]\rightarrow [AEa]a&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
# &amp;lt;math&amp;gt;[AEa]\rightarrow a&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kuroda normal form ==&lt;br /&gt;
Every context-sensitive grammar which does not generate the empty string can be transformed into a [[weak equivalence (formal languages)|weakly equivalent]] one in [[Kuroda normal form]]. &amp;quot;Weakly equivalent&amp;quot; here means that the two grammars generate the same language. The normal form will not in general be context-sensitive, but will be a [[noncontracting grammar]].&amp;lt;ref&amp;gt;{{cite journal | first=Sige-Yuki | last=Kuroda | author-link=S.-Y. Kuroda | title=Classes of languages and linear-bounded automata | journal=Information and Control | volume=7 | number=2 | pages=207–223 | date=June 1964 | doi=10.1016/s0019-9958(64)90120-2| doi-access=free }}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{cite book |last1=Mateescu | first1=Alexandru |last2=Salomaa|first2=Arto |author-link2=Arto Salomaa|editor1-first=Grzegorz| editor1-last=Rozenberg|editor-link1=Grzegorz Rozenberg |editor2-first=Arto| editor2-last=Salomaa |editor-link2=Arto Salomaa|title=Handbook of Formal Languages. Volume I: Word, language, grammar |publisher=Springer-Verlag |year=1997 |pages=175–252 |chapter=Chapter 4: Aspects of Classical Language Theory |isbn=3-540-61486-9}}, Here: Theorem 2.2, p. 190&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Kuroda normal form is an actual normal form for non-contracting grammars.&lt;br /&gt;
&lt;br /&gt;
== Properties and uses ==&lt;br /&gt;
{{see also|context-sensitive language}}&lt;br /&gt;
{{more citations needed section|date=August 2014}}&lt;br /&gt;
&lt;br /&gt;
=== Equivalence to linear bounded automaton ===&lt;br /&gt;
A formal language can be described by a context-sensitive grammar if and only if it is accepted by some [[linear bounded automaton]] (LBA).&amp;lt;ref&amp;gt;(Hopcroft, Ullman, 1979); Theorem 9.5, 9.6, p.&amp;amp;nbsp;225–226&amp;lt;/ref&amp;gt; In some textbooks this result is attributed solely to Landweber and [[S.-Y. Kuroda|Kuroda]].&amp;lt;ref name=&amp;quot;DavisSigal1994b&amp;quot;/&amp;gt; Others call it the [[John Myhill|Myhill]]–Landweber–Kuroda theorem.&amp;lt;ref name=&amp;quot;flac&amp;quot;&amp;gt;{{Cite web |first=Klaus |last=Sutner |url=https://www.cs.cmu.edu/~flac/pdf/ContSens.pdf |title=Context Sensitive Grammars |publisher=[[Carnegie Mellon University]] |date=Spring 2016 |access-date=2019-08-29 |archive-date=2017-02-03 |archive-url=https://web.archive.org/web/20170203081505/http://www.cs.cmu.edu/~flac/pdf/ContSens.pdf |url-status=dead }}&amp;lt;/ref&amp;gt; (Myhill introduced the concept of deterministic LBA in 1960. Peter S. Landweber published in 1963 that the language accepted by a deterministic LBA is context sensitive.&amp;lt;ref&amp;gt;{{cite journal | author=P.S. Landweber | title=Three Theorems on Phrase Structure Grammars of Type 1 | journal=[[Information and Control]] | volume=6 | number=2 | pages=131&amp;amp;ndash;136 | year=1963 |doi=10.1016/s0019-9958(63)90169-4 | doi-access=free }}&amp;lt;/ref&amp;gt; Kuroda introduced the notion of non-deterministic LBA and the equivalence between LBA and CSGs in 1964.&amp;lt;ref&amp;gt;{{cite book|first=Alexander|last=Meduna|author-link=Alexander Meduna|title=Automata and Languages: Theory and Applications|url=https://books.google.com/books?id=s7gEErax71cC&amp;amp;pg=PA755|year=2000|publisher=Springer Science &amp;amp; Business Media|isbn=978-1-85233-074-3|page=755}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{cite book|first=Willem J. M.|last=Levelt|author-link=Willem Levelt|title=An Introduction to the Theory of Formal Languages and Automata|url=https://books.google.com/books?id=tFvtwGYNe7kC&amp;amp;pg=PA126|year=2008|publisher=John Benjamins Publishing|isbn=978-90-272-3250-2|pages=126–127}}&amp;lt;/ref&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
{{As of|2010}}{{update inline|date=May 2023}} it is still an open question whether every context-sensitive language can be accepted by a &#039;&#039;deterministic&#039;&#039; LBA.&amp;lt;ref&amp;gt;{{cite book|last=Martin|first=John C.|title=Introduction to Languages and the Theory of Computation|year=2010|publisher=McGraw-Hill|location=New York, NY|isbn=9780073191461|edition=4th|page=283}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Closure properties ===&lt;br /&gt;
Context-sensitive languages are closed under [[complement (set theory)|complement]]. This 1988 result is known as the [[Immerman–Szelepcsényi theorem]].&amp;lt;ref name=&amp;quot;flac&amp;quot;/&amp;gt;&lt;br /&gt;
Moreover, they are closed under [[union (set theory)|union]], [[intersection (set theory)|intersection]], [[concatenation#Concatenation of sets of strings|concatenation]], [[String substitution|substitution]],&amp;lt;ref group=note&amp;gt;more formally: if &#039;&#039;L&#039;&#039; ⊆ Σ&amp;lt;sup&amp;gt;*&amp;lt;/sup&amp;gt; is a context-sensitive language and &#039;&#039;f&#039;&#039; maps each &#039;&#039;a&#039;&#039;∈Σ to a context-sensitive language &#039;&#039;f&#039;&#039;(&#039;&#039;a&#039;&#039;), the &#039;&#039;f&#039;&#039;(&#039;&#039;L&#039;&#039;) is again a context-sensitive language&amp;lt;/ref&amp;gt; [[inverse string homomorphism|inverse homomorphism]], and [[Kleene plus]].&amp;lt;ref&amp;gt;(Hopcroft, Ullman, 1979); Exercise S9.10, p.&amp;amp;nbsp;230–231&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every [[recursively enumerable language]] &#039;&#039;L&#039;&#039; can be written as &#039;&#039;h&#039;&#039;(&#039;&#039;L&#039;&#039;) for some context-sensitive language &#039;&#039;L&#039;&#039; and some [[string homomorphism]] &#039;&#039;h&#039;&#039;.&amp;lt;ref&amp;gt;(Hopcroft, Ullman, 1979); Exercise S9.14, p.&amp;amp;nbsp;230–232. &#039;&#039;h&#039;&#039; maps each symbol to itself or to the empty string.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational problems ===&lt;br /&gt;
The [[decision problem]] that asks whether a certain string &#039;&#039;s&#039;&#039; belongs to the language of a given context-sensitive grammar &#039;&#039;G&#039;&#039;, is [[PSPACE-complete]]. Moreover, there are context-sensitive grammars whose languages are PSPACE-complete. In other words, there is a context-sensitive grammar &#039;&#039;G&#039;&#039; such that deciding whether a certain string &#039;&#039;s&#039;&#039; belongs to the language of &#039;&#039;G&#039;&#039; is PSPACE-complete (so &#039;&#039;G&#039;&#039; is fixed and only &#039;&#039;s&#039;&#039; is part of the input of the problem).&amp;lt;ref&amp;gt;An example of such a grammar, designed to solve the [[QSAT]] problem, is given in {{Cite book|last=Lita|first=C. V.|title=2016 18th International Symposium on Symbolic and Numeric Algorithms for Scientific Computing (SYNASC) |chapter=On Complexity of the Detection Problem for Bounded Length Polymorphic Viruses |date=2016-09-01|pages=371–378|doi=10.1109/SYNASC.2016.064|isbn=978-1-5090-5707-8|s2cid=18067130}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The [[emptiness problem]] for context-sensitive grammars (given a context-sensitive grammar &#039;&#039;G&#039;&#039;, is &#039;&#039;L&#039;&#039;(&#039;&#039;G&#039;&#039;)=∅ ?) is [[Undecidable language|undecidable]].&amp;lt;ref&amp;gt;(Hopcroft, Ullman, 1979); Exercise S9.13, p.&amp;amp;nbsp;230–231&amp;lt;/ref&amp;gt;&amp;lt;ref group=note&amp;gt;This also follows from (1) [[#top|context-free languages being also context-sensitive]], (2) [[#Closure properties|context-sensitive language being closed under intersection]], but (3) [[Context-free grammar#Language disjointness|disjointness of context-free languages being undecidable]].&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== As model of natural languages ===&lt;br /&gt;
Savitch has [[mathematical proof|proven]] the following theoretical result, on which he bases his criticism of CSGs as basis for natural language: for any [[recursively enumerable]] set &#039;&#039;R&#039;&#039;, there exists a context-sensitive language/grammar &#039;&#039;G&#039;&#039; which can be used as a sort of proxy to test membership in &#039;&#039;R&#039;&#039; in the following way: given a string &#039;&#039;s&#039;&#039;, &#039;&#039;s&#039;&#039; is in &#039;&#039;R&#039;&#039; if and only if there exists a positive integer &#039;&#039;n&#039;&#039; for which &#039;&#039;sc&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;&#039;&#039; is in G, where &#039;&#039;c&#039;&#039; is an arbitrary symbol not part of &#039;&#039;R&#039;&#039;.&amp;lt;ref name=&amp;quot;Vide1999&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It has been shown that nearly all [[natural language]]s may in general be characterized by context-sensitive grammars, but the whole class of CSGs seems to be much bigger than natural languages.{{citation needed|date=November 2011}}  Worse yet, since the aforementioned decision problem for CSGs is PSPACE-complete, that makes them totally unworkable for practical use, as a polynomial-time algorithm for a PSPACE-complete problem would imply [[P=NP problem|P=NP]].&lt;br /&gt;
&lt;br /&gt;
It was proven that some natural languages are not context-free, based on identifying so-called [[cross-serial dependency|cross-serial dependencies]] and [[unbounded scrambling]] phenomena.{{cn|date=December 2022}} However this does not necessarily imply that the class of CSGs is necessary to capture &amp;quot;context sensitivity&amp;quot; in the colloquial sense of these terms in natural languages. For example, [[linear context-free rewriting system]]s (LCFRSs) are strictly weaker than CSGs but can account for the phenomenon of cross-serial dependencies; one can write a LCFRS grammar for {&#039;&#039;a&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;b&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;c&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;d&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;&#039;&#039; | &#039;&#039;n&#039;&#039; ≥ 1} for example.&amp;lt;ref&amp;gt;{{cite web|url=http://user.phil-fak.uni-duesseldorf.de/~kallmeyer/GrammarFormalisms/4nl-cfg.pdf |archive-url=https://web.archive.org/web/20140819085139/http://user.phil-fak.uni-duesseldorf.de/~kallmeyer/GrammarFormalisms/4nl-cfg.pdf |archive-date=2014-08-19 |url-status=live|title=Mildly Context-Sensitive Grammar Formalisms: Natural Languages are not Context-Free|first=Laura|last=Kallmeyer|year=2011}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{cite web|url=http://user.phil-fak.uni-duesseldorf.de/~kallmeyer/GrammarFormalisms/4lcfrs-intro.pdf |archive-url=https://web.archive.org/web/20140819085928/http://user.phil-fak.uni-duesseldorf.de/~kallmeyer/GrammarFormalisms/4lcfrs-intro.pdf |archive-date=2014-08-19 |url-status=live|title=Mildly Context-Sensitive Grammar Formalisms: Linear Context-Free Rewriting Systems|first=Laura|last=Kallmeyer|year=2011}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;Kallmeyer2010&amp;quot;&amp;gt;{{cite book|first=Laura|last=Kallmeyer|title=Parsing Beyond Context-Free Grammars|year=2010|publisher=Springer Science &amp;amp; Business Media|isbn=978-3-642-14846-0|pages=1–5}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ongoing research on [[computational linguistics]] has focused on formulating other classes of languages that are &amp;quot;[[mildly context-sensitive language|mildly context-sensitive]]&amp;quot; whose decision problems are feasible, such as [[tree-adjoining grammar]]s, [[combinatory categorial grammar]]s, [[coupled context-free language]]s, and [[Generalized context-free grammar#Linear Context-free Rewriting Systems (LCFRSs)|linear context-free rewriting system]]s.  The languages generated by these formalisms properly lie between the context-free and context-sensitive languages.&lt;br /&gt;
&lt;br /&gt;
More recently, the class [[PTIME]] has been identified with [[range concatenation grammar]]s, which are now considered to be the most expressive of the mild-context sensitive language classes.&amp;lt;ref name=&amp;quot;Kallmeyer2010&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Chomsky hierarchy]]&lt;br /&gt;
* [[Growing context-sensitive grammar]]&lt;br /&gt;
* [[Definite clause grammar#Non-context-free grammars]]&lt;br /&gt;
* [[List of parser generators for context-sensitive grammars]]&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
{{reflist|group=note}}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist}}&lt;br /&gt;
&lt;br /&gt;
==Further reading==&lt;br /&gt;
* {{cite book|first1=Alexander|last1=Meduna|author-link1=Alexander Meduna|first2=Martin|last2=Švec|title=Grammars with Context Conditions and Their Applications|year=2005|publisher=John Wiley &amp;amp; Sons|isbn=978-0-471-73655-4}}&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
* [https://web.archive.org/web/20110708224600/https://danielmattosroberts.com/earley/context-sensitive-earley.pdf Earley Parsing for Context-Sensitive Grammars]&lt;br /&gt;
&lt;br /&gt;
{{Formal languages and grammars}}&lt;br /&gt;
&lt;br /&gt;
{{DEFAULTSORT:Context-Sensitive Grammar}}&lt;br /&gt;
[[Category:Formal languages]]&lt;br /&gt;
[[Category:Grammar frameworks]]&lt;/div&gt;</summary>
		<author><name>129.101.71.84</name></author>
	</entry>
</feed>