Unit - 3
Context-sensitive languages
Q. 1) What is the context - sensitive grammar?
Ans : Context - sensitive grammar
A Context-sensitive grammar is an Unrestricted grammar in which all the productions are of form –
𝛂 ➝ β
Where 𝛂 ,β ∈ (V u T) and |𝛂| ≤ | β |
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
Q. 2) Write short notes on context - sensitive language ?
Ans : 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.
Q. 3) Define linear bounded automata ?
Ans : Linear bounded automata
A linear bounded automaton is a multi-track non-deterministic Turing machine with a tape of some bounded finite length.
Length = function (Length of the initial input string, constant c)
Here,
Memory information ≤ c × Input information
The calculation is confined to the steady limited territory. The information letters in
Order contains two uncommon images which fill in as left end markers and right end
Markers which mean the advances neither one of the moves to one side of the left
End marker nor to one side of the correct end marker of the tape.
A linear bounded automaton can be defined as an 8-tuple
(Q, X, ∑, q0, ML, MR, δ, F)
Where −
● Q is a finite set of states
● X is the tape alphabet
● ∑ is the input alphabet
● q0 is the initial state
● ML is the left end marker
● MR is the right end marker where MR ≠ ML
● δ is a transition function which maps each pair (state, tape symbol) to (state,
Tape symbol, Constant ‘c’) where c can be 0 or +1 or -1
● F is the set of final states
A deterministic linear bounded automaton is always context-sensitive and the linear bounded automaton with empty language is undecidable.
Q. 4) Write any example of CSG ?
Ans : Example of CSG
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 {an bn cn | n≥1}.
Q. 5) Write closure properties of context sensitive language ?
Ans : They are closed under -
● Union
If λ ∉ L1 ∪ L2, then let
G = (N1 ∪ N2 ∪ {S}, T, S, P1 ∪ P2 ∪ {S → S1, S → S2}),
Where S ∉ N1 ∪ N2, a new symbol.
It can be seen that G generates the language L1 ∪ L2
● Concatenation
If λ ∉ L1 and λ ∉ L2, then let
G = (N1 ∪ N2 ∪ {S}, T, S, P1 ∪ P2 ∪ {S → S1S2}),
Where S ∉ N1 ∪ N2 a new symbol.
It can be easily seen that G generates the language L1L2.
Q. 6) What of the following is the most general phase - structured grammar ?
A) regular
B) Context - sensitive
C) Context - free
D) None of the above
Ans : correct answer is “ B “.