![]() |
VOOZH | about |
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 β → α γ β
- X ➜ non-terminal symbol
- α and β ➜ strings of terminals and/or non-terminals
- γ ➜ non-empty string
- X is replaced by γ only in the context of α and β
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.
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 :
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={ anbncn ∣ n≥1 }