language-icon Old Web
English
Sign In

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. Context-sensitive grammars are more general than context-free grammars, in the sense that there are languages that can be described by CSG but not by context-free grammars. Context-sensitive grammars are less general (in the same sense) than unrestricted grammars. Thus, CSG are positioned between context-free and unrestricted grammars in the Chomsky hierarchy. 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. Context-sensitive grammars are more general than context-free grammars, in the sense that there are languages that can be described by CSG but not by context-free grammars. Context-sensitive grammars are less general (in the same sense) than unrestricted grammars. Thus, CSG are positioned between context-free and unrestricted grammars in the Chomsky hierarchy. 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, although this is not how Noam Chomsky defined them in 1959. This choice of definition makes no difference in terms of the languages generated (i.e. 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. 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 'context-sensitive' as misleading and proposed 'non-erasing' as better explaining the distinction between a CSG and an unrestricted grammar. Although it is well-known that certain features of languages (e.g. cross-serial dependency) are not context-free, it is an open question how much of CSG's 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 languages. The syntaxes of some visual programming languages can be described by context-sensitive graph grammars. A formal grammar G = (N, Σ, P, S), where N is a set of nonterminal symbols, Σ is a set of terminal symbols, P is a set of production rules, and S is the start symbol, is context-sensitive if all rules in P are of the form where A ∈ N, α,β ∈ (N∪Σ)* and γ ∈ (N∪Σ)+. A string u ∈ (N∪Σ)* directly yields, or directly derives to, a string v ∈ (N∪Σ)*, denoted as u ⇒ v, if u can be written as lαAβr, and v can be written as lαγβr, for some production rule (αAβ→αγβ) ∈ P, and some context strings l, r ∈ (N∪Σ)*.More generally, u is said to yield, or derive to, v, denoted as u ⇒* v, if u = u1 ⇒ ... ⇒ un = v for some n≥0 and some strings u2, ..., un-1 (N∪Σ)*. That is, the relation (⇒*) is the reflexive transitive closure of the relation (⇒). The language of the grammar G is the set of all terminal symbol strings derivable from its start symbol, formally: L(G) = { w ∈ Σ*: S ⇒* w }.Derivations that do not end in a string composed of terminal symbols only are possible, but don't contribute to L(G). The only difference between this definition of Chomsky and that of unrestricted grammars is that γ can be empty in the unrestricted case.

[ "Context-free grammar", "Tree-adjoining grammar", "c-command", "Definite clause grammar", "Unrestricted grammar", "Van Wijngaarden grammar", "Matrix grammar" ]
Parent Topic
Child Topic
    No Parent Topic