Context-sensitive grammar
ID: context-sensitive-grammar
A context-sensitive grammar has productions of the form , where is a nonterminal symbol and is a nonempty word. The surrounding words specify the context in which replacement is permitted. Every such step is length-nondecreasing.
An equivalent language-class description uses arbitrary noncontracting production rules with and a nonterminal in . If the empty word is included, the customary exception is with start symbol absent from every right side. Individual noncontracting rules need not have the displayed context-preserving form, although the generated language classes agree.
For example, replaces only when its immediate context is on the left and on the right. The language is context-sensitive and is not a context-free language. The associated computational model is a linear bounded automaton, whose usable tape is bounded by a constant times input length.
Context-sensitive grammar (CSG) is a type of formal grammar that is more powerful than context-free grammar (CFG) and is used in the field of formal language theory, a branch of computer science and linguistics. In a context-sensitive grammar, the production rules are sensitive to the context of non-terminal symbols. This means that the rules can add complexity to the generated strings based on the surrounding symbols.
New to topics? Read the docs here!