Context Sensitive Grammar Habeeb and Alvin ATC Seminar 30 NOV 2018 - - PowerPoint PPT Presentation

context sensitive grammar
SMART_READER_LITE
LIVE PREVIEW

Context Sensitive Grammar Habeeb and Alvin ATC Seminar 30 NOV 2018 - - PowerPoint PPT Presentation

Context Sensitive Grammar Habeeb and Alvin ATC Seminar 30 NOV 2018 Habeeb and Alvin CSG 30 NOV 2018 1 / 15 Overview Introduction 1 Formal definition 2 Context Sensitive Language 3 Examples Closure properties 4 Relation Between


slide-1
SLIDE 1

Context Sensitive Grammar

Habeeb and Alvin

ATC Seminar

30 NOV 2018

Habeeb and Alvin CSG 30 NOV 2018 1 / 15

slide-2
SLIDE 2

Overview

1

Introduction

2

Formal definition

3

Context Sensitive Language Examples

4

Closure properties

5

Relation Between Recursive and CSL

Habeeb and Alvin CSG 30 NOV 2018 2 / 15

slide-3
SLIDE 3

Definition

A context sensitive grammar (CSG) is a grammar where all productions are of the form αAβ → αγβ where γ = ǫ During derivation non-terminal A will be replaced by γ only when it is present in context of α and β. This definition shows clearly one aspect of this type of grammar; it is noncontracting, in the sense that the length of successive sentential forms can never decrease.

Habeeb and Alvin CSG 30 NOV 2018 3 / 15

slide-4
SLIDE 4

Formal definition

A context sensitive grammar G = (N, Σ, P, S) , where

N is a set of nonterminal symbols Σ is a set of terminal symbols S is the start symbol, and P is a set of production rules, of the form αAβ → αγβ where A in N, α, β ∈ (N ∪ Σ)∗ and γ ∈ (N ∪ Σ)+

The production S → ǫ is also allowed if S is the start symbol and it does not appear on the right side of any production.

Habeeb and Alvin CSG 30 NOV 2018 4 / 15

slide-5
SLIDE 5

Context Sensitive Language

A language L is said to be context-sensitive if there exists a context-sensitive grammar G, such that L = L(G). If G is a Context Sensitive Grammar then, L(G) = {w| (w ∈ Σ∗) ∧

  • S ⇒+

G w

  • }

Habeeb and Alvin CSG 30 NOV 2018 5 / 15

slide-6
SLIDE 6

Context Sensitive Language : Example

  • Example. The following grammar(G) is context-sensitive

S → aTb|ab aT → aaTb|ac L(G) = {ab} ∪ {ancbn|n > 0}

Habeeb and Alvin CSG 30 NOV 2018 6 / 15

slide-7
SLIDE 7

Context Sensitive Language

L(G) = {ab} ∪ {ancbn|n > 0} This language is also a context-free. For example, Context free grammar(G1) for this. S → aTb|ab T → aTb|c Any context-free language is context sensitive Not all context-sensitive languages are context-free.

Habeeb and Alvin CSG 30 NOV 2018 7 / 15

slide-8
SLIDE 8

Context Sensitive Language : Example

Example

L = {anbncn|n > 0}

Habeeb and Alvin CSG 30 NOV 2018 8 / 15

slide-9
SLIDE 9

Context Sensitive Language : Example

Example

L = {anbncn|n > 0} Context sensitive grammar(G)

  • 1. S → aBC
  • 2. S → aSBC
  • 3. aB → ab
  • 4. bB → bb
  • 5. bc → bc
  • 6. cC → cc
  • 7. CB → CZ
  • 8. CZ → WZ
  • 9. WZ → WC
  • 10. WC → BC

Habeeb and Alvin CSG 30 NOV 2018 9 / 15

slide-10
SLIDE 10

Closure properties

Context Sensitive Languages are closed under

Union Intersection Complement Concatenation Kleene closure

Habeeb and Alvin CSG 30 NOV 2018 10 / 15

slide-11
SLIDE 11

Closure properties : Union

Let G1 = (N1, T1, P1, S1) and G2 = (N2, T2, P2, S2), s.t L (G1) = L1 and L (G2) = L2. Construct G = (S ∪ N1 ∪ N2, T1 ∪ T2, {S → S1, S → S2} ∪ P1 ∪ P2, S) s.t N1 ∩ N2 = ∅ and S / ∈ {N1 ∪ N2}. G also CSG and any derivation has the form S ⇒ Si ⇒∗

Gi w ∈ L (Gi)

for some i ∈ {1, 2} We can derive only words and all words of L (G1) ∪ L (G2) = L1 ∪ L2 Therefore L1 ∪ L2 = L(G) ∈ L(CS)

Habeeb and Alvin CSG 30 NOV 2018 11 / 15

slide-12
SLIDE 12

Closure properties : Concatenation

Let G1 = (N1, T1, P1, S1) and G2 = (N2, T2, P2, S2), s.t L (G1) = L1 and L (G2) = L2. Construct G = (S ∪ N1 ∪ N2, T, {S → S1S2} ∪ P1 ∪ P2, S) s.t N1 ∩ N2 = ∅ and S / ∈ {N1 ∪ N2} Any derivation in G has the form S ⇒ S1S2 ⇒∗

G1 w1S2 ⇒∗ G2 w1w2

S ⇒ wi is a derivation in Gi . i.e. the derivation only uses rules of Pi . The derivations in G1 and G2 cannot be influenced by the contexts of the other part. So G is a context sensitive grammar, L(G) is a CSL.

Habeeb and Alvin CSG 30 NOV 2018 12 / 15

slide-13
SLIDE 13

Relation Between Recursive and CSL

Theorem

Every context-sensitive language L is recursive. For CSL L, CSG G, Derivation of w S ⇒ x1 ⇒ x2 ⇒ x3 · · · · ⇒ w has bound on no of steps.(Bound on possible derivations). We know that |xi| ≤ |xi+1| (G is non contracting). We can check whether w is in L(G) as follows Construct a transition graph whose vertices are the strings of length ≤ |w| Paths correspond to derivation in grammars. Add edge from x to y if x ⇒ y w ∈ L(G) iff there is a path from S to w

Habeeb and Alvin CSG 30 NOV 2018 13 / 15

slide-14
SLIDE 14

References

An Introduction to Formal Languages and Automata by Peter Linz https: / / en. wikipedia. org/wiki/Context-sensitive grammar https://gyires.inf.unideb.hu/GyBITT/14/index.html

  • ld seminars.

Habeeb and Alvin CSG 30 NOV 2018 14 / 15

slide-15
SLIDE 15

The End

Habeeb and Alvin CSG 30 NOV 2018 15 / 15