Open in App
Not now

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

• Difficulty Level : Medium
• Last Updated : 20 Nov, 2019

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 {anbncn | 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

My Personal Notes arrow_drop_up
Related Articles