Contextsensitive Grammar (CSG) and Language (CSL) (original) (raw)

Context-sensitive Grammar (CSG) and Language (CSL)

Last Updated : 12 Feb, 2026

Context-Sensitive Grammar (CSG) is a formal grammar where production rules depends on the context of a symbols, a non-terminal can be replaced only when it appears in a specific context.

Production Rules

α X β → α γ β

Context-sensitive grammars are more powerful than context-free grammars because there are some languages that can be described by CSG but not by context-free grammars and CSL are less powerful than Unrestricted grammar. That's why context-sensitive grammars are positioned between context-free and unrestricted grammars in the Chomsky hierarchy.

3815828

A Context-Sensitive Grammar is defined as a 4-tuple:

**G = (N, Σ, P, S )

All productions in **P are of form:

**α 1 A α 2 --> α 1 β α 2

**Context-sensitive Language: The language that can be defined by context-sensitive grammar is called CSL. Properties of CSL are :

Example:

Consider the following Context-Sensitive Grammar (CSG):

**S → abc | aAbc
**Ab → bA
**Ac → Bbcc
**bB → Bb
**aB → aa | aaA

What is the language generated by this grammar?

Solution:

S
⇒ aAbc
⇒ abAc
⇒ abBbcc
⇒ aBbbcc
⇒ aaAbbcc
⇒ aabAbcc
⇒ aabbAcc
⇒ aabbBbccc
⇒ aabBbbccc
⇒ aaBbbbccc
⇒ aaabbbccc

The language generated by this grammar is: L={ anbncn ∣ n≥1 }

L={ a n b n c n **∣ n≥1 }

  1. GATE CS 2005, Question 55
  2. GATE CS 2004, Question 87