**Context-Sensitive Grammar – **

A Context-sensitive grammar is an Unrestricted grammar in which all the productions are of form –

Where α and β are strings of non-terminals and terminals.

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.

Context-sensitive grammar has 4-tuples. **G = {N, Σ, P, S}**, Where

N = Set of non-terminal symbols

Σ = Set of terminal symbols

S = Start symbol of the production

P = Finite set of productions

All rules in P are of the 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 :

- Union, intersection and concatenation of two context-sensitive languages is context-sensitive.
- Complement of a context-sensitive language is context-sensitive.

**Example –**

Consider the following 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 {**a ^{n}b^{n}c^{n}** | n≥1}.

**GATE CS Corner Questions**

Practicing the following questions will help you test your knowledge. All questions have been asked in GATE in previous years or in GATE Mock Tests. It is highly recommended that you practice them.

**References –**

CSG – Wikipedia

CSG – csa.iisc.ernet.in

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

## Recommended Posts:

- Relationship between grammar and language in Theory of Computation
- Regular Expressions, Regular Grammar and Regular Languages
- Ambiguity in Context free Grammar and Context free Languages
- Ambiguity in Context free Grammar and Context free Languages
- Removing Direct and Indirect Left Recursion in a Grammar
- Difference between Ambiguous and Unambiguous Grammar
- Operator grammar and precedence parser in TOC
- Ambiguous Grammar
- Converting Context Free Grammar to Chomsky Normal Form
- Converting Context Free Grammar to Greibach Normal Form
- Regular Expression Vs Context Free Grammar
- CYK Algorithm for Context Free Grammar
- Language Processors: Assembler, Compiler and Interpreter
- Star Height of Regular Expression and Regular Language
- NPDA for the language L ={w∈ {a,b}*| w contains equal no. of a's and b's}
- Hypothesis (language regularity) and algorithm (L-graph to NFA) in TOC
- NPDA for accepting the language L = {a
^{n}b^{m}| n,m ≥ 1 and n ≠ m} - Construct a DFA which accept the language L = {w | w ∈ {a,b}* and Na(w) mod 3 = Nb (w) mod 3}
- Construct a Turing Machine for language L = {a^n b^m c^nm where n >=0 and m >= 0}
- C Language | Set 1

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.