Download presentation

Presentation is loading. Please wait.

Published byAnis Gardner Modified over 8 years ago

1
Phrase-structure grammar A phrase-structure grammar is a quadruple G = (V, T, P, S) where V is a finite set of symbols called nonterminals, T is a set of terminals, P is the set of productions → , (V T)*V(V T)*, (V T)*, S is a member of V called the start symbol.

2
S → ABC AB → aAD AB → bAE DC → BaC EC → BbC Da → aD Db → bD Ea → aE Eb → bE AB → C → aB → Ba bB → Bb

3
Context-sensitive Grammar Definition: A grammar G = (V, T, P, S) is context sensitive if | | | | for every production in P. Definition: A “true” context sensitive grammar G = (V, T, P, S) is a grammar in which each production is of the form A , where and are in (V T) *, in (V T) +, and A in V. The production A is also written as A / _

4
Example: S ABC S ABCS AB BA AC CA BC CB BA AB CA AC CB BC A a B b C c

5
1)S ASCB 2)S ACB 3)CB CR 4)CR BR 5)BR BC 6)AB Ab 7)Ab ab 8)Aa aa 9)bB bb 10)bC bc 11)cC cc

6
Definition: A language L is context- sensitive language if it is generated by a context-sensitive grammar. Theorem: Every context-sensitive language can be generated by a true context-sensitive grammar.

7
Step 1: convert all rules of the grammar G to the form where is a string of non terminals, let G 1 be the new grammar replace a by N a and add a production N a a, where N a is a new nonterminal Step 2: Let w(G) = max {| |, where is in P} Convert the grammar G 1 to a grammar G 2 such that V + and w(G 2 ) 2

8
Let : A 1 …A m B 1.. B n be a production If n 2, add it to G 2 If 2 m < n, create two productions: A 1 … A m B 1 … B m-1 X X B m … B n If m = 1 and n 3 create n-1 productions A 1 B 1 X 1 X 1 B 2 X 2 … X n-2 B n-1 B n

9
If m = n and n 3, create the n-1 productions A 1 A 2 B 1 X 1 X 1 A 3 B 2 X 2 … X n-2 A n B n-1 B n Step 3: Convert G 2 to a new grammar G 3 Add productions of the form A to G 3 If AB CD is a production and if A= C or B = D, add to G 3 if AB CD and A C and B D, then add the productions AB XB, XB XY, XY CY CY CD

10
Definition: Let G = (V, T, P, S) be a context-sensitive grammar and let w T n for some n 1. Define a sequence of sets W i (V T) * as follows: W 0 = {S} for each i 0, W i+1 = W i { (V T) + | in G, is in W i, and | | n}

11
Proposition: Let W i be as defined before. Then we have the following: 1) for each i 0, W i W i+1 2) if W k = W k+1 for some k, W k = W k+m for all m > 0 3) for each i 0, W i = { (V T) * | S m , | | n, m i} 4) there exists k < max(2*|V T| n, n+1) such that W k = W k+1 5) let k be the least integer such that W k = W k+1, then W k = { (V T) + | S * , | | n}

12
Theorem: Let G = (V, T, P, S) be a context- sensitive grammar. Then there is an algorithm which, given any w T *, decides whether or not w L(G). (L(G) is recursive)

Similar presentations

© 2024 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google