What is a context sensitive language in TOC?

Data Structure AlgorithmsComputer ScienceComputers

A context-sensitive grammar whose productions are of the form

αAβ → αγβ

Where α, β ∈ (N ∪ T)*, A ∈ N; γ ∈ (N ∪ T)+ and a rule of the form S → λ is allowed if the start symbol S do not appear on the right hand side of any rule.

The language generated by such a grammar is called a context-sensitive language.

  • Every context-free grammar is also context-sensitive =⇒ the context-free languages are a subset of the context-sensitive languages (see Chomsky Normal Form).

  • But, not every context-sensitive language is context-free.


The language {anbncn, n > 1} is context-sensitive but not context free.

A grammar for this language is given by:
S → aSBC | aBC,
CB → HB,
HB → HC,
HC → BC,
aB → ab,
bB → bb,
bC → bc,
cC → cc
A derivation e.g. aabbcc, using this grammar is:
S ⇒ aSBC
   ⇒ aaBCBC (using S → aBC)
   ⇒ aabCBC (using aB → ab)
   ⇒ aabHBC (using CB → HB)
   ⇒ aabHCC (using HB → HC)
   ⇒ aabBCC (using HC → BC)
   ⇒ aabbCC (using bB → bb)
   ⇒ aabbcC (using bC → bc)
   ⇒ aabbcc (using cC → cc)

The context-sensitive languages can also be generated by a monotonic grammar, any production is allowed, as long as there are no rules for making strings shorter (except one S → ∧)!

Published on 15-Jun-2021 13:17:53