0% found this document useful (0 votes)
9 views4 pages

Application of Context Sensitive Grammar

Uploaded by

ganindita452
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Application of Context Sensitive Grammar

Uploaded by

ganindita452
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Properties of Context Sensitive Grammar

• 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.

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

Type 2: Context Free Context Free Pushdown Automaton A -> y

Type 3: Regular Regular Finite State Automaton A -> a and A -> aB

In short:

• Recursively enumerable Language is the largest set.


• Context Sensitive Language is a subset of Recursively enumerable Language
• Context Free Language is a subset of Context Sensitive Language
• Regular Language is a subset of Context Free Language

Application of Context Sensitive Grammar

• Context Sensitive Grammar is more powerful than Context Free Grammar.


• Natural Language cannot be modeled using Context Free Grammar but it can be generated using
Context Sensitive Grammar.

The problem is Context Sensitive Grammar is:


• The grammar required for Natural Language is substantially weaker than CSG.
• Decision problem for CSG is PSPACE-complete.
For this reason, Context Sensitive Grammar is not usually used to generate Natural Language but it can be
used to do so easily as every Natural Language can be modeled as a CSG.

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.

Definition of Context Sensitive Grammar

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.

Context Sensitive Grammar is defined as a 4 tuple G = (V, T, P, S) where:


1. V is a finite set of elements known as variables (non-terminal symbols).
2. T is a finite set of elements known as terminals
3. P - It is a set of production rules,
4. V ∩ T = Null (empty set)
5. S is an element of V and is known as start variable.
6. It is context sensitive if all the rules in production are in the form –
αAβ → αγβ
where, A ∈ V, α,β ∈ (V∪T)*, γ ∈ (V∪T)+
Note the difference from Context Free Grammar is in the Production Rules P only.

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.

R is the set of following Rules:


S -> aTb
S -> ab
aT -> aaTb
aT -> ac
The corresponding Context Sensitive Language is as follows:

L(G) = {ab} union {ancbn | n > 0}


A language which can be generated by both Context Sensitive Grammar and Context Free Grammar

 
 
 
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

2. The language {am bn Cm+n | m, n ≥ 1} is


(A) regular
(B) context-free but not regular
(C) context sensitive but not context free
(D) type-0 but not context sensitive

You might also like