In formal language theory, a grammar is noncontracting (or monotonic) if for all of its production rules,
α → β (where α and β are strings of nonterminal and terminal symbols), it holds that
|α| ≤ |β|, that is β has at least as many symbols as α.
A grammar is essentially noncontracting if there may be one exception, namely, a rule
S → ε
where S is the start symbol and ε the empty string, and furthermore, S never occurs in the right-hand side of any rule.
A context-sensitive grammar is a noncontracting grammar in which all rules are of the form αAβ → αγβ, where A is a nonterminal, and γ is a nonempty string of nonterminal and/or terminal symbols.
However, some authors use the term context-sensitive grammar to refer to noncontracting grammars in general.[1]
Chomsky (1959) introduced the Chomsky hierarchy, in which context-sensitive grammars occur as "type 1" grammars; general noncontracting grammars do not occur.[2]
Chomsky (1963) calls a noncontracting grammar a "type 1 grammar", and a context-sensitive grammar a "type 2 grammar", and by presenting a conversion from the former into the latter, proves the two weakly equivalent .[3]
Kuroda (1964) introduced Kuroda normal form, into which all noncontracting grammars can be converted.[4]
Example
S
→
abc
S
→
aSBc
cB
→
Bc
bB
→
bb
This grammar, with the start symbol S, generates the language
{ anbncn : n ≥ 1 },[5]
which is not context-free due to the pumping lemma.
A context-sensitive grammar for the same language is shown below.
converting any noncontracting grammar in Kuroda normal form into a context-sensitive grammar.
Hence, these three types of grammar are equal in expressive power, all describing exactly the context-sensitive languages that do not include the empty string; the essentially noncontracting grammars describe exactly the set of context-sensitive languages.
A direct conversion
A direct conversion into context-sensitive grammars, avoiding Kuroda normal form:
For an arbitrary noncontracting grammar (N, Σ, P, S), construct the context-sensitive grammar (N’, Σ, P’, S) as follows:
For every terminal symbol a ∈ Σ, introduce a new nonterminal symbol [a] ∈ N’, and a new rule ([a] → a) ∈ P’.
In the rules of P, replace every terminal symbol a by its corresponding nonterminal symbol [a]. As a result, all these rules are of the form X1...Xm → Y1...Yn for nonterminals Xi, Yj and m≤n.
Replace each rule X1...Xm → Y1...Yn with m>1 by 2m rules:[note 1]
X1
X2
...
Xm-1
Xm
→
Z1
X2
...
Xm-1
Xm
Z1
X2
...
Xm-1
Xm
→
Z1
Z2
...
Xm-1
Xm
:
Z1
Z2
...
Xm-1
Xm
→
Z1
Z2
...
Zm-1
Xm
Z1
Z2
...
Zm-1
Xm
→
Z1
Z2
...
Zm-1
Zm
Ym+1
...
Yn
Z1
Z2
...
Zm-1
Zm
Ym+1
...
Yn
→
Y1
Z2
...
Zm-1
Zm
Ym+1
...
Yn
Y1
Z2
...
Zm-1
Zm
Ym+1
...
Yn
→
Y1
Y2
...
Zm-1
Zm
Ym+1
...
Yn
:
Y1
Y2
...
Zm-1
Zm
Ym+1
...
Yn
→
Y1
Y2
...
Ym-1
Zm
Ym+1
...
Yn
Y1
Y2
...
Ym-1
Zm
Ym+1
...
Yn
→
Y1
Y2
...
Ym-1
Ym
Ym+1
...
Yn
where each Zi ∈ N’ is a new nonterminal not occurring elsewhere.[7][8]
For example, the above noncontracting grammar for { anbncn | n ≥ 1 } leads to the following context-sensitive grammar (with start symbol S) for the same language:
^Chomsky, N. 1959a. On certain formal properties of grammars. Information and Control 2: 137–67. (141–42 for the definitions)
^Noam Chomsky (1963). "Formal properties of grammar". In R.D. Luce and R.R. Bush and E. Galanter (ed.). Handbook of Mathematical Psychology. Vol. II. New York: Wiley. pp. 323–418. Here: pp. 360–363 and 367
Mateescu, Alexandru; Salomaa, Arto (1997). "Chapter 4: Aspects of Classical Language Theory". In Rozenberg, Grzegorz; Salomaa, Arto (eds.). Handbook of Formal Languages. Volume I: Word, language, grammar. Springer-Verlag. pp. 175–252. ISBN3-540-61486-9.
Each category of languages, except those marked by a *, is a proper subset of the category directly above it.Any language in each category is generated by a grammar and by an automaton in the category in the same line.