You are on page 1of 4

Module 4

Context sensitive grammars

Context –sensitive Grammars

A formal grammar known as a CSG allows any production rules’ left and right sides to be
surrounded by a context of the terminal as well as nonterminal symbols.

SG is a 4 tuple grammar G. Here, G = (V, Σ, R, S), where:

 Σ refers to the element’s finite set known as terminals.


 V refers to the element’s finite set known as variables.
 S refers to V’s element, and it is known as the start variable.
 V ∩ Σ = Null (empty set).
 R refers to a fine element’s set known as Production Rules. Every rule is like xXy -> xby
in which the X is in V, b is in (V union Σ)+, and x and y are in (V union Σ).
Please take note that the Production Rules R are the only area where Context Free Grammar
differs.
Only for the starting symbol that appears only on the rule’s left side is the rule S -> empty
permitted.

Properties of Context Sensitive Grammar


Properties of Context Sensitive Grammar are:

 All CFLs are CSLs (Context Sensitive Languages).


 Not all CSLs are CFLs.
 A weakly similar Kuroda Normal Form Context Sensitive Grammar can be created from
any Context Sensitive Grammar (CSG) that does not produce an empty string. Weakly
equivalent means that the set of CSL produced by both Context Sensitive Grammars is
the same.
 If and only if the language’s strings are accepted by a linear bounded automaton (LBA),
the language is formed using Context Sensitive Grammar.
 A PSPACE-complete algorithm exists to determine whether a given Context Sensitive
Grammar G can generate a given string, STR. This indicates that the problem is difficult,
and if it can be solved in polynomial time, it will imply that P = NP, a long-standing issue
in computer science.

Application of Context Sensitive Grammar


The grammar that is Context Sensitive is more effective than grammar that is context-free.
Context Sensitive Grammar can be used to create Natural Language, whereas Context Free
Grammar cannot.
Context Sensitive Grammar has the following issues:

 The grammar required for Natural Language is substantially weaker than CSG.
 The CSG decision problem is PSPACE-complete.
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}.

linear bounded automaton

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 computation is restricted to the constant bounded area. The input alphabet contains two
special symbols which serve as left end markers and right end markers which mean the
transitions neither move to the left of the left end marker nor to the right of the right 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..

Equivalence with CFG

You might also like