Context Sensitive and Unrestricted Grammars

 

🌿 Context-Sensitive Grammar (CSG)

Definition

A context-sensitive grammar (CSG) is a formal grammar
G=(V,Σ,R,S) where every production (rule) in RR is of the form:

αAβαγβ\alpha A \beta \rightarrow \alpha \gamma \beta

such that AVΣA \in V - \Sigma, α,β(VΣ)\alpha, \beta \in (V \cup \Sigma)^*, and
γ(VΣ)+.

That means:

  • The nonterminal A can be replaced by γ,

  • But only in the context of α (on the left) and β (on the right).

  • Also, the length of the right-hand side is at least the length of the left-hand side:

    αAβαγβ|\alpha A \beta| \leq |\alpha \gamma \beta|

    — so no production makes the string shorter.

This non-decreasing length property makes them context-sensitive.


Intuitive Meaning

  • The replacement (rewriting) of a symbol depends on its context in the string.

  • Hence the name “context-sensitive.”

  • The grammar cannot “shrink” a string (unlike context-free grammars).


Language Type

The language generated by a context-sensitive grammar is called a Context-Sensitive Language (CSL).


Equivalent Machine Model

Context-sensitive languages are exactly those accepted by a
Linear Bounded Automaton (LBA)
that is, a nondeterministic Turing machine whose tape head never goes beyond the space occupied by the input.

This was shown by Kuroda (1964).


Example

Language:

L={anbncnn1}L = \{ a^n b^n c^n \mid n \ge 1 \}

This language is not context-free, but context-sensitive.

Grammar GG:

SaSBCaBCS \Rightarrow aSBC \mid aBC
CBBCCB \Rightarrow BC
aBabaB \Rightarrow ab
bCbcbC \Rightarrow bc

How it works:

  • Start by generating strings like anBnCna^n B^n C^n

  • Then use CBBCCB \Rightarrow BC to reorder the middle symbols.

  • Finally, use aBabaB \Rightarrow ab and bCbcbC \Rightarrow bc to turn B’s and C’s into the corresponding terminals.

So this grammar enforces equal numbers of a’s, b’s, and c’s — a classic context-sensitive pattern.


Key Properties of CSG

  1. Every context-free grammar is also a CSG (so, CSG ⊇ CFG).

  2. No CSG can derive the empty string (unless the start symbol is specially handled).

  3. Every context-sensitive language is recursive — that is, decidable by some Turing machine.

  4. Recognized by Linear Bounded Automata (LBA).


🌾 Unrestricted Grammar (Type-0 Grammar)

Definition

An unrestricted grammar (also called a Type-0 grammar) is the most general kind of grammar.

A grammar
G=(V,Σ,R,S)G = (V, \Sigma, R, S)
is unrestricted if the productions are of the form:

αβ\alpha \rightarrow \beta

where:

  • α,β(VΣ)\alpha, \beta \in (V \cup \Sigma)^*

  • and α contains at least one nonterminal.

Unlike CSG:

  • There is no restriction on context or on string length —
    so β|\beta| can be less than, equal to, or greater than α|\alpha|


Language Type

The languages generated by unrestricted grammars are called recursively enumerable languages (RE languages).


Equivalent Machine Model

An unrestricted grammar is equivalent to a Turing machine.

That is:

  • For every unrestricted grammar, there exists a Turing machine that accepts the same language.

  • And for every Turing machine, there is an unrestricted grammar generating the same language.

So Type-0 grammars = Turing machine languages.


Example

Language:

L={anbncnn1}L = \{ a^n b^n c^n \mid n \ge 1 \}

We can also define it by an unrestricted grammar, for example:

SaSBCabcS \rightarrow aSBC \mid abc
CBBCCB \rightarrow BC
aBabaB \rightarrow ab
bCbcbC \rightarrow bc

Notice — this looks similar to our context-sensitive example, but if we also allowed rules that shorten strings or rearrange them arbitrarily, it becomes unrestricted.


Properties of Unrestricted Grammars

  1. Most powerful of all grammars.

  2. Generate recursively enumerable languages (those accepted by a Turing machine that may not halt).

  3. No restriction on rule length or form.

  4. Used to describe any computation that can be done mechanically (by Turing’s thesis).


🧭 3. Relationship — Chomsky Hierarchy

TypeGrammar NameMachine EquivalentLanguage ClassRestrictions
0Unrestricted GrammarTuring MachineRecursively EnumerableNone
1Context-Sensitive GrammarLinear Bounded AutomatonContext-SensitiveNon-contracting rules
2Context-Free GrammarPushdown AutomatonContext-FreeA → α
3Regular GrammarFinite AutomatonRegularA → aB or A → a

And:

RegularContext-FreeContext-SensitiveRecursively Enumerable\text{Regular} \subset \text{Context-Free} \subset \text{Context-Sensitive} \subset \text{Recursively Enumerable}

Comments

Popular posts from this blog

Theory Of Computation PCCST302 KTU Semester 3 BTech 2024 Scheme

Non deterministic Finite Automata NFA

Formal Definition - Turing Machine