Application of Context Sensitive Grammar
Application of Context Sensitive Grammar
This table gives the idea of the different Grammars in Theory of Computation, known as Chomsky Hierarchy
and was first formed in 1956:
AUTOMATA GRAMMAR
TYPE GRAMMAR MACHINE RULES
Recursively
Type 0: Unrestricted Enumerable Turing Machine a -> b
Type 1: Context Sensitive Context Sensitive Linear Bounded Automaton aAb -> ayb
In short:
Natural Languages are produced using “Linear Context-Free Rewriting Systems,” a less effective
variation of Context Sensitive Grammar.
Research in Computational Linguistics is on producing classes of languages that are weaker than Context
Sensitive but stronger than Context Free so that the decision problem can be solved in feasible time. This has
resulted in many grammars like Combinatory Categorial Grammar, Tree Adjoining Grammar, Linear
Context Free Rewriting Systems, Range Concatenation Grammar and others.
The Context Sensitive Grammar is formal grammar in which the left-hand sides and right-hand
sides of any production rules may be surrounded by a context of terminal and non-
terminal grammar. It is less general than Unrestricted Grammar and more general than Context Free
Grammar.
The rule S -> empty is allowed only for the starting symbol appearing only on the left side of the rule.
Context Sensitive Language (IMPORTANT)
1. The language generated by the context-sensitive grammar is called Context
Sensitive
Language. Context
Sensitive
Language has the following properties -
2. Union, intersection and concatenation of two context-sensitive languages is context-sensitive.
3. The Kleene plus of a context-sensitive language is context-sensitive.
4. Complement of a context-sensitive language is context-sensitive
5. Every context-sensitive language is recursive.
Examples of Context Sensitive Grammar
Example 1
Example of a Context Sensitive Grammar:
G = (V, Σ, R, S)
V = {S, T}
Σ = {a, b, c}
S is the starting symbol.
Example 2 (IMPORTANT)
Consider a Language where anbncn.
For this, we need Context Sensitive Grammar.
We cannot generate this language with Context Free Grammar because it keeps track of only two properties
while in this case, we have 3 properties that is count of a, b and c. Similarly, Regular Grammar cannot be used
as it is weaker than Context Free Grammar and tracks only 1 property.
Solution:
The rules of Context Sensitive Grammar for this language will be:
S -> aSBC|aBC
aB -> ab
cB -> Bc (Special Type 1 rule)
bB -> bb
bC ->bc
cC ->cc
For example, if N=3, then the resultant string will be aaabbbccc and the derivation using our Context Sensitive
Grammar will be:
S->aSBC
-> aaSBCBC (using Rule: S->aSBc)
-> aaaBCBCBC (using Rule: S->aBc)
-> aaabCBCBC (using Rule: aB->ab)
-> aaabcBCBC (using Rule: bC->bc)
-> aaabBcCBC (using Rule: bB->bb)
-> aaabbcCBC (using Rule: cC->cc)
-> aaabbccBC (using Rule: cB->Bc)
-> aaabbcBcC (using Rule: cB->Bc)
-> aaabbBccC (using Rule: bB->bb)
-> aaabbbccC (using Rule: cC->cc)
-> aaabbbccc
With this, we have our resultant string aaabbbccc.
Note, this Language cannot be generated by Context Free Grammar or Regular Grammar but this is possible
with Context Sensitive Grammar which is more powerful.
3. Example 3
Example of a Context Sensitive Grammar:
G = (V, Σ, R, S)
V = {S, T}
Σ = {a, b, c}
S is the starting symbol.
L(G) = {ancbn | n > 0}
Solution:
S -> aTb
aT -> aaTb
aT -> ac
1. Consider the languages:
L1 = {anbncm | n, m > 0} L2 = {anbmcm | n, m > 0}
Which one of the following statements is FALSE?
(A) L1 ∩ L2 is a context-free language
(B) L1 U L2 is a context-free language
(C) L1 and L2 are context-free language
(D) L1 ∩ L2 is a context sensitive language