Context-sensitive grammar
A context-sensitive grammar (CSG) is a formal grammar in which the left-hand sides and right-hand sides of any production rules may be surrounded by a context of terminal and nonterminal symbols.[5] Context-sensitive grammars are more general than context-free grammars, in the sense that there are languages that can be described by a CSG but not by a context-free grammar.[5] Context-sensitive grammars are less general (in the same sense) than unrestricted grammars.[5] Thus, CSGs are positioned between context-free and unrestricted grammars in the Chomsky hierarchy.[5] 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.[15] Some textbooks actually define CSGs as non-contracting, although this is not how Noam Chomsky defined them in 1959.[src] This choice of definition makes no difference in terms of the languages generated (i.e.[src] the two definitions are 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.[4] 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.…[5]
A context-sensitive grammar (CSG) is a formal grammar in which the left-hand sides and right-hand sides of any production rules may be surrounded by a context of terminal and nonterminal symbols.[5] Context-sensitive grammars are more general than context-free grammars, in the sense that there are languages that can be described by a CSG but not by a context-free grammar.[5] Context-sensitive grammars are less general (in the same sense) than unrestricted grammars.[5] Thus, CSGs are positioned between context-free and unrestricted grammars in the Chomsky hierarchy.[5] 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.[15] Some textbooks actually define CSGs as non-contracting, although this is not how Noam Chomsky defined them in 1959.[src] This choice of definition makes no difference in terms of the languages generated (i.e.[src] the two definitions are 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.[4] 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.[5] Walter Savitch has criticized the terminology "context-sensitive" as misleading and proposed "non-erasing" as better explaining the distinction between a CSG and an unrestricted grammar.[15] Although it is well known that certain features of languages (e.g.[src] cross-serial dependency) are not context-free, it is an open question how much of CSGs' expressive power is needed to capture the context sensitivity found in natural languages.[5] Subsequent research in this area has focused on the more computationally tractable mildly context-sensitive languages.[5] The syntaxes of some visual programming languages can be described by context-sensitive graph grammars.[5] ==Formal definition== Let us notate a formal grammar as G = (N, \Sigma, P, S) , with N a set of nonterminal symbols, \Sigma a set of terminal symbols, P a set of production rules, and S \in N the start symbol.[src] A string u \in (N \cup \Sigma)^* directly yields, or directly derives to, a string v \in (N \cup \Sigma)^* , denoted as u \Rightarrow v , if v can be obtained from u by an application of some production rule in P, that is, if u = \gamma L \delta and v = \gamma R \delta , where (L \to R) \in P is a production rule, and \gamma, \delta \in (N \cup \Sigma)^* is the unaffected left and right part of the string, respectively.[src] More generally, u is said to yield, or derive to, v, denoted as u \Rightarrow^* v , if v can be obtained from u by repeated application of production rules, that is, if u = u_0 \Rightarrow ...[src] \Rightarrow u_n = v for some n ≥ 0 and some strings u_1, ..., u_{n-1} \in (N \cup \Sigma)^* .[src] In other words, the relation \Rightarrow^* is the reflexive transitive closure of the relation \Rightarrow .[src] The language of the grammar G is the set of all terminal-symbol strings derivable from its start symbol, formally: L(G) = \{ w \in \Sigma^* \mid S \Rightarrow^* w \} .[src] Derivations that do not end in a string composed of terminal symbols only are possible, but do not contribute to L(G).[src] A non contracting grammar (for which there is an equivalent CSG) for the language L_{Cross} = \{ a^mb^nc^{m}d^{n} \mid m \ge 1, n \ge 1 \} is defined by p_0 : S \rightarrow RT , p_1 : R\rightarrow aRC | aC , p_3 : T\rightarrow BTd | Bd , p_5 : CB\rightarrow BC , p_6 : aB\rightarrow ab , p_7 : bB\rightarrow bb , p_8 : Cd\rightarrow cd , and p_9 : Cc\rightarrow cc .[src] With these definitions, a derivation for a^3b^2c^3d^2 is: S \Rightarrow_{p_0} RT \Rightarrow_{p^{2}_{1}p_{2}} a^3C^3T \Rightarrow_{p_{3}p_{4} } a^3C^3B^2d^2 \Rightarrow_{p^{6}_{5} } a^3B^2C^3d^2 \Rightarrow_{p_{6}p_{7} } a^3b^2C^3d^2 \Rightarrow_{p_{8}p^{2}_{9}} a^3b^2c^3d^2 .[src] The emptiness problem for context-sensitive grammars (given a context-sensitive grammar G, is L(G)=∅ ?) is undecidable.[4] It has been shown that nearly all natural languages may in general be characterized by context-sensitive grammars, but the whole class of CSGs seems to be much bigger than natural languages.[5] 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.[src] It was proven that some natural languages are not context-free, based on identifying so-called cross-serial dependencies and unbounded scrambling phenomena.[5] However this does not necessarily imply that the class of CSGs is necessary to capture "context sensitivity" in the colloquial sense of these terms in natural languages.[5] For example, linear context-free rewriting systems (LCFRSs) are strictly weaker than CSGs but can account for the phenomenon of cross-serial dependencies; one can write a LCFRS grammar for {a n b n c n d n | n ≥ 1} for example.[15] Ongoing research on computational linguistics has focused on formulating other classes of languages that are "mildly context-sensitive" whose decision problems are feasible, such as tree-adjoining grammars, combinatory categorial grammars, coupled context-free languages, and linear context-free rewriting systems.[5] The languages generated by these formalisms properly lie between the context-free and context-sensitive languages.[5] More recently, the class PTIME has been identified with range concatenation grammars, which are now considered to be the most expressive of the mild-context sensitive language classes.[5] ==See also== Chomsky hierarchy Growing context-sensitive grammar Definite clause grammar#Non-context-free grammars List of parser generators for context-sensitive grammars ==Notes== ==References== ==Further reading== ==External links== Earley Parsing for Context-Sensitive Grammars[15]
42 sentences · 42 cited inline · 15 references stored
References
- Linz, Peter. An Introduction to Formal Languages and Automata . Jones & Bartlett Publishers . 2011. · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "Linz, Peter. An Introduction to Formal Languages and Automata . Jones & Bartlett Publishers . 2011." Linz, Peter. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "Linz, Peter. An Introduction to Formal Languages and Automata . Jones & Bartlett Publishers . 2011." Linz, Peter. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA Linz, Peter. (2026). Linz, Peter. An Introduction to Formal Languages and Automata . Jones & Bartlett Publishers . 2011. Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
- Hazewinkel, Michiel. Encyclopaedia of Mathematics . Springer Science & Business Media . 1989. · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "Hazewinkel, Michiel. Encyclopaedia of Mathematics . Springer Science & Business Media . 1989." Hazewinkel, Michiel. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "Hazewinkel, Michiel. Encyclopaedia of Mathematics . Springer Science & Business Media . 1989." Hazewinkel, Michiel. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA Hazewinkel, Michiel. (2026). Hazewinkel, Michiel. Encyclopaedia of Mathematics . Springer Science & Business Media . 1989. Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
- Ito, Masami. Automata, Formal Languages and Algebraic Systems: Proceedings of AFLAS 2008, Kyoto, Japan, 20– . · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "Ito, Masami. Automata, Formal Languages and Algebraic Systems: Proceedings of AFLAS 2008, Kyoto, Japan, 20– ." Ito, Masami. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "Ito, Masami. Automata, Formal Languages and Algebraic Systems: Proceedings of AFLAS 2008, Kyoto, Japan, 20– ." Ito, Masami. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA Ito, Masami. (2026). Ito, Masami. Automata, Formal Languages and Algebraic Systems: Proceedings of AFLAS 2008, Kyoto, Japan, 20– . Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
- Context Sensitive Grammars . · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "Context Sensitive Grammars ." 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "Context Sensitive Grammars ." 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA encyclopegia.org. (2026). Context Sensitive Grammars . Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
- It has been shown that nearly all natural languages may in general be characterized by context-sensitive grammars, but the whole class of CSGs seems to be much bigger than natural languages.cita . · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "It has been shown that nearly all natural languages may in general be characterized by context-sensitive grammars, but the whole class of CSGs seems to be much bigger than natural languages.cita ." It has been shown that nearly all natural languages may in general be characterized by context-sensitive grammars, but t. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "It has been shown that nearly all natural languages may in general be characterized by context-sensitive grammars, but the whole class of CSGs seems to be much bigger than natural languages.cita ." It has been shown that nearly all natural languages may in general be characterized by context-sensitive grammars, but t. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA It has been shown that nearly all natural languages may in general be characterized by context-sensitive grammars, but t. (2026). It has been shown that nearly all natural languages may in general be characterized by context-sensitive grammars, but the whole class of CSGs seems to be much bigger than natural languages.cita . Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
- user.phil-fak.uni-duesseldorf.de . · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "user.phil-fak.uni-duesseldorf.de ." user. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "user.phil-fak.uni-duesseldorf.de ." user. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA user. (2026). user.phil-fak.uni-duesseldorf.de . Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
- web.archive.org . (archived copy) · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "web.archive.org . (archived copy)." web. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "web.archive.org . (archived copy)." web. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA web. (2026). web.archive.org . (archived copy). Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
- Meduna, Alexander. Automata and Languages: Theory and Applications . 2000. · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "Meduna, Alexander. Automata and Languages: Theory and Applications . 2000." Meduna, Alexander. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "Meduna, Alexander. Automata and Languages: Theory and Applications . 2000." Meduna, Alexander. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA Meduna, Alexander. (2026). Meduna, Alexander. Automata and Languages: Theory and Applications . 2000. Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
- Davis, Martin. Computability, Complexity, and L . · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "Davis, Martin. Computability, Complexity, and L ." Davis, Martin. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "Davis, Martin. Computability, Complexity, and L ." Davis, Martin. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA Davis, Martin. (2026). Davis, Martin. Computability, Complexity, and L . Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
- Levelt, Willem J. M. An Introduction to the Theory of Formal Languages and Automata . · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "Levelt, Willem J. M. An Introduction to the Theory of Formal Languages and Automata ." Levelt, Willem J. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "Levelt, Willem J. M. An Introduction to the Theory of Formal Languages and Automata ." Levelt, Willem J. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA Levelt, Willem J. (2026). Levelt, Willem J. M. An Introduction to the Theory of Formal Languages and Automata . Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
- Davis, Martin. Computability, Complexity, and . · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "Davis, Martin. Computability, Complexity, and ." Davis, Martin. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "Davis, Martin. Computability, Complexity, and ." Davis, Martin. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA Davis, Martin. (2026). Davis, Martin. Computability, Complexity, and . Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
- Chomsky, N. Handbook of Mathematical Psychology . 1963. · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "Chomsky, N. Handbook of Mathematical Psychology . 1963." Chomsky, N. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "Chomsky, N. Handbook of Mathematical Psychology . 1963." Chomsky, N. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA Chomsky, N. (2026). Chomsky, N. Handbook of Mathematical Psychology . 1963. Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
- Issues in Mathematical Linguistics: Workshop on Mathematical Linguistics, State College, Pa., April 1998 . · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "Issues in Mathematical Linguistics: Workshop on Mathematical Linguistics, State College, Pa., April 1998 ." Issues in Mathematical Linguistics: Workshop on Mathematical Linguistics, State College, Pa. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "Issues in Mathematical Linguistics: Workshop on Mathematical Linguistics, State College, Pa., April 1998 ." Issues in Mathematical Linguistics: Workshop on Mathematical Linguistics, State College, Pa. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA Issues in Mathematical Linguistics: Workshop on Mathematical Linguistics, State College, Pa. (2026). Issues in Mathematical Linguistics: Workshop on Mathematical Linguistics, State College, Pa., April 1998 . Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
- Zhang, Da-Qian, Kang Zhang, and Jiannong Cao. "[https://web.archive.org/web/20180323220143/https://pdfs.semanticscholar.org/5d3d/217d73e0f6bbeefa3749c16fbc7b2e00ec0b.pdf A context-sensitive graph gram . (archived copy) · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "Zhang, Da-Qian, Kang Zhang, and Jiannong Cao. "[https://web.archive.org/web/20180323220143/https://pdfs.semanticscholar.org/5d3d/217d73e0f6bbeefa3749c16fbc7b2e00ec0b.pdf A context-sensitive graph gram . (archived copy)." Zhang, Da-Qian, Kang Zhang, and Jiannong Cao. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "Zhang, Da-Qian, Kang Zhang, and Jiannong Cao. "[https://web.archive.org/web/20180323220143/https://pdfs.semanticscholar.org/5d3d/217d73e0f6bbeefa3749c16fbc7b2e00ec0b.pdf A context-sensitive graph gram . (archived copy)." Zhang, Da-Qian, Kang Zhang, and Jiannong Cao. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA Zhang, Da-Qian, Kang Zhang, and Jiannong Cao. (2026). Zhang, Da-Qian, Kang Zhang, and Jiannong Cao. "[https://web.archive.org/web/20180323220143/https://pdfs.semanticscholar.org/5d3d/217d73e0f6bbeefa3749c16fbc7b2e00ec0b.pdf A context-sensitive graph gram . (archived copy). Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
- The name context-sensitive is explained by the α and β that form the context of A and determine whether A can be replaced with γ or not. By contrast, in a context-free grammar, no cont . · retrieved 2026-08-10 · rev 1368790723
Cite this reference
MLA "The name context-sensitive is explained by the α and β that form the context of A and determine whether A can be replaced with γ or not. By contrast, in a context-free grammar, no cont ." The name context-sensitive is explained by the α and β that form the context of A and determine whether A can be replace. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723. Accessed 03 December 2026.
Chicago "The name context-sensitive is explained by the α and β that form the context of A and determine whether A can be replaced with γ or not. By contrast, in a context-free grammar, no cont ." The name context-sensitive is explained by the α and β that form the context of A and determine whether A can be replace. 2026-08-10. https://en.wikipedia.org/w/index.php?oldid=1368790723.
APA The name context-sensitive is explained by the α and β that form the context of A and determine whether A can be replace. (2026). The name context-sensitive is explained by the α and β that form the context of A and determine whether A can be replaced with γ or not. By contrast, in a context-free grammar, no cont . Retrieved December 3, 2026, from https://en.wikipedia.org/w/index.php?oldid=1368790723
Cite this article
MLA
"Context-sensitive grammar." encyclopegia.org, 2026, https://encyclopegia.org/wiki/context-sensitive-grammar. Accessed 03 December 2026.
Chicago
"Context-sensitive grammar." encyclopegia.org. Accessed December 3, 2026. https://encyclopegia.org/wiki/context-sensitive-grammar.
APA
encyclopegia.org. (2026). Context-sensitive grammar. Retrieved December 3, 2026, from https://encyclopegia.org/wiki/context-sensitive-grammar
Accessed December 3, 2026 · CC BY-SA 4.0 · citation page · JSON