งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

ไวยกรณ์ไม่พึง บริบท CONTEXT-FREE GRAMMARS. วัตถุประสงค์ A context-free grammar (CFG) is a simple recursive method of specifying grammar rules by which.

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "ไวยกรณ์ไม่พึง บริบท CONTEXT-FREE GRAMMARS. วัตถุประสงค์ A context-free grammar (CFG) is a simple recursive method of specifying grammar rules by which."— ใบสำเนางานนำเสนอ:

1 ไวยกรณ์ไม่พึง บริบท CONTEXT-FREE GRAMMARS

2 วัตถุประสงค์ A context-free grammar (CFG) is a simple recursive method of specifying grammar rules by which strings in a language can be generated. To a large extent, they are capable of specifying the syntax of high-level programming languages and other formal languages. CONTEXT-FREE GRAMMARS

3 DESCRIBE THE LANGUAGES การนิยามภาษา Using recursive definition to describe any languages (regular or nonregular). Example, palindrome language. Alphabet  = { a, b} Rule1: , a, b  PALINDROME Rule2:For any S  PALINDROME, then aSa, bSb are in PALINDROME. Note: S can be considered as a variable, representing an arbitrary element of PALINDROME. CONTEXT-FREE GRAMMARS

4 Alphabet  = { a, b} Rule1: , a, b  PALINDROME Rule2:For any S  PALINDROME, then aSa, bSb are in PALINDROME. S can be considered as a variable, representing an arbitrary element of PALINDROME. Rule can be considered as a relation, representing a transformation, denoted by “  ”. Rule1: S   | a | b Rule2: S  aSa | bSb Note: The vertical bar “|” means “or”. , a and b are terminals. S is a nonterminal or variable. DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

5 ตัว แปร The production of the grammar SStart variable. others represent some auxiliary class of strings. (class of recursive definition). DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

6 Alphabet  = {a, b} L is defined by the following rules: S  aSa | bSb | V V  aTb | bTa T  aT | bT |  Some words generated by these rules, S  aSa  aVa  abTaa  abaa. S  aSa  abSba  abVba  abaTbba  abaabba. NONPALINDROME ตัวอย่ าง DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

7 A context-free grammar (CFG) is a 4-tiple G = (V, , S, P) where V and  are disjoint finite sets, S is an element of V and P is a finite set of formulas of the form A  , where A  V and   (V   )*. S: start symbol V: set of variables or nonterminals  : alphabet or set of terminals. P: set of grammar rules or productions. นิยาม DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

8 G = (V, , S, P) Alphabet  = {a, b} L is defined by the following rules: S  aSa | bSb | V V  aTb | bTa T  aT | bT |  aVa  G abTaadenotes abTaa can be obtained from aVa by one of the productions in G ( V  bTa ). S  * G aaabadenotes aaaba is derived from S in zero or more steps in G. ตัวอย่ าง DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

9 Let G = (V, , S, P) be a CFG. The language generated by G is L(G) = { x   * | S  * G x }. A language L is a Context-free language (CFL) if there is a CFG G so that L = L(G). A string x  (V   )* is a sentential form of G if there is a derivation S  * G x in G. A string x   * is a sentence of G if there is a derivation S  * G x in G. คำ ศัพธ์ DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

10 ? To demonstrate that a CFG generates a language, we must show two things: 1.every string in the language can be derived from the grammar 2.no other string can be. ปัญห า DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

11 น่าคิด โจทย์ น่าคิด ? กำหนดให้ ภาษาบรรยาย โดย  * จงเขียน ไวยกรณ์ไม่พึง บริบท ของภาษานี้

12 น่าคิด โจทย์ น่าคิด ? กำหนดให้ ภาษา เมื่อ n  0 กำหนดให้ ภาษา 0 n 1 n เมื่อ n  0 { , 01, 0011, , … } จงเขียน ไวยกรณ์ไม่พึง บริบท ของภาษานี้

13 น่าคิด โจทย์ น่าคิด ? กำหนดให้ ภาษาบรรยาย โดย (0+001)*(10+111)*1 จงเขียน ไวยกรณ์ไม่พึง บริบท ของภาษานี้

14 L = { x  {0,1}* | n 0 (x) = n 1 (x) }. (n i (x) = number of i’s of x.) Clearly that  is in this language.Rule1: S   One way to produce other strings in L, add one 0 and one 1. Rule2: S  0S1 Rule3: S  1S0 Consider strings which do not start and end with the same symbol. Example, or These strings can be obtained by the concatenation of two strings in L. Rule4: S  SS. Example, can be obtained from 01 and ตัวอย่ าง DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

15 Conclusion Let G = (V, , S, P) with S  0S1 | 1S0 | SS | . We have that L(G)  L. L = { x  {0,1}* | n 0 (x) = n 1 (x) }. (n i (x) = number of i’s of x.) ตัวอย่ าง DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

16 Now we will show that L  L(G) where G = (V, , S, P) with S  0S1 | 1S0 | SS | . By mathematical induction on |x|. Let d(x) = n 0 (x) – n 1 (x). Basic step: if |x| = 0 and x  L then d(x) = 0, x = . Of course, x  L(G) by S  . L = { x  {0,1}* | n 0 (x) = n 1 (x) }. (n i (x) = number of i’s of x.) พิสูจ น์ DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

17 Inductive step: for |x|≤ k, d(x) = 0, x  L. Let x  L and |x| = k+1. Case1:x begins with 0, ends with 1, then x = 0y1 and y  L(G). Then S  * G y. Since S  0S1, we also have x  L(G). Case2:x begins with 1, ends with 0, similar to the case 1. Case3: x begins with 1, ends with 1, then x = 1y1 and d(x) = 0. d(1) = -1 and d(1y) = 1, then  u such that u is a prefix of 1y, d(u) = 0. x = uw, u and w  L and L(G). Since S  SS, x  L(G). Case4:x begins with 0, ends with 0, similar to the case 3.Q.E.D. L = { x  {0,1}* | n 0 (x) = n 1 (x) }. (n i (x) = number of i’s of x.) พิสูจ น์ DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

18 L = { x  {0,1}* | n 0 (x)  n 1 (x) }. (n i (x) = number of i’s of x.) ตัวอย่ าง DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS Let L 0 bethe language of strings with more 0’s than 1’s. Let L 1 be the language of strings with more 1’s than 0’s. Then L = L 0  L 1.

19 Consider L 0. Clearly that 0  L 0, and for any x in L 0, 0x and x0 are in L 0. This suggests the production S  0 | 0S | S0. 1 should be introduced in L 0. Consider two strings x and y in L 0, xy is at least two more 0’s than 1’s. Therefore adding a single 1 will still yield an element of L 0. ThenG 0 = (V, , S, P) S  0 | 0S | S0 | 1SS | S1S | SS1. It is clear that L(G 0 )  L 0. L = { x  {0,1}* | n 0 (x)  n 1 (x) }. (n i (x) = number of i’s of x.) พิสูจ น์ DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

20 Now prove that L 0  L(G 0 ). S  0 | 0S | S0 | 1SS | S1S | SS1. By mathematical induction on |x| in L 0. Basic step: |x| = 1 and x  L 0, x = 0. Since S  0, then x  L(G 0 ). Inductive step: |x|≤ k, d(x) > 0 then x  L(G 0 ). For x  L 0 and |x| = k+1 and d(x) > 0. Case x = 0y0. Rewrite x = w i 1z i, for 1  i  n; n = 1’s. if d(w n )>0 then x is obtained by starting S  S1S. ( d(w n )>0 and d(z n )>0, w n and z n  L 0 ). L = { x  {0,1}* | n 0 (x)  n 1 (x) }. (n i (x) = number of i’s of x.) พิสูจ น์ DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

21 Inductive step: |x|≤ k, d(x) > 0 then x  L(G 0 ). For x  L 0 and |x| = k+1 and d(x) > 0. Case x = 0y0. Rewrite x = w i 1z i, for 1  i  n; n = 1’s. if d(w n )>0 then x is obtained by starting S  S1S. ( d(w n )>0 and d(z n )>0, w n and z n  L 0 ). if d(w n )  0 then  m that d(w m )  0 (d(w 1 )>0) and also d(w m-1 ) = 1. Then d(w m-1 )> 0 and d(z m-1 )>0. x is obtained by starting S  S1S. L = { x  {0,1}* | n 0 (x)  n 1 (x) }. (n i (x) = number of i’s of x.) พิสูจ น์ DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

22 Context-free grammar of this language is the following: S  A | B A  0 | 0A | 1AA | A1A | AA1 B  1 | 1B | 0BB | B0B | BB0 L = { x  {0,1}* | n 0 (x)  n 1 (x) }. (n i (x) = number of i’s of x.) พิสูจ น์ DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

23 ALGEBRAIC EXPRESSION Context-free grammar of this language is the following: S  S+S | S-S | S  S | S  S | (S) | a where a is a terminal symbol. ตัวอย่ าง DESCRIBE THE LANGUAGES การนิยามภาษา CONTEXT-FREE GRAMMARS

24 For any context-free languages L 1 and L 2, the languages L 1  L 2, L 1 L 2 and L 1 * are also context-free languages. ทฤษฎี บท CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS

25 Let  = { 0, 1 }. Consider two context-free grammars, G 1 = (V 1, , S 1, P 1 ) and G 2 = (V 2, , S 2, P2). P 1 = { S 1  XA, X  0, A  0 } P 2 = ( S 2  XB, X  1, B  1 }. Find G = G 1  G 2. L(G 1 ) = { 00 } and L(G 2 ) = { 11 }. S  S 1 | S 2 S 1  XAS 2  XB X  0 X  1 A  0 B  1 01  L(G 1 )  L(G 2 ) But S  * 01. CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS แนวคิ ด

26 L(G 1 ) = { 00 } and L(G 2 ) = { 11 }. S  S 1 | S 2 S 1  XAS 2  YB X  0 Y  1 A  0 B  1 Let  = { 0, 1 }. Consider two context-free grammars, G 1 = (V 1, , S 1, P 1 ) and G 2 = (V 2, , S 2, P2). P 1 = { S 1  XA, X  0, A  0 } P 2 = ( S 2  XB, X  1, B  1 }. Find G = G 1  G 2. CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS แนวคิ ด

27 For any context-free languages L 1 and L 2, the languages L 1  L 2, L 1 L 2 and L 1 * are also context-free languages. ทฤษฎี บท CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS

28 Case: L 1  L 2 V = V 1  V 2  { S } P = P 1  P 2  { S  S 1 | S 2 } Case: L 1 L 2 V = V 1  V 2  { S } P = P 1  P 2  { S  S 1 S 2 } Case: L 1 *V = V 1  { S } P = P 1  { S  S 1 S |  } ทฤษฎี บท CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS

29 ? Is every regular language a context-free language ? CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS

30 By definition of regular language, , {  }and { a } are regular languages, and regular is closed under union, concatenation and Kleene’s star. To prove this theorem, we have to show that any regular can be produced by some context-free grammars. ทฤษฎี บท CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS Every regular language is a context-free language.

31 From the regular expression, we have S  XYX represents (011+1)* Y represents (01)* X  011X | 1X |  Y  01Y |  Example: can be derived from CFG. Regular language (011+1)*(01)* ตัวอย่ าง CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS

32 This language can be considered as 0 i 1 i 1 m 1 k 0 k for m > 0. S  XYZX represents 0 i 1 i Y represents 1 m Z represents 1 k 0 k X  0X1 |  Y  1Y | 1 Z  1Z0 |  ตัวอย่ าง Let L be the language { 0 i 1 j 0 k | j > i + k }. Find the context-free grammar for L. CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS

33 Understanding the sentence begins with understanding its grammatical structure ( i.e., knowing how it is derived from the grammar rules ). DERIVATION TREE ความ เข้าใจ CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS

34 How the sentence can be generated? Given a CFG S  XY X  011X | 1X |  Y  01Y |  S XY 011X01Y 1 X Y  011 X ต้นไม้ CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS DERIVATION TREE

35 ความ กำกวม AMBIGUOUS A context-free grammar G is ambiguous if there is at least one string in L(G) having two or more distinct derivation trees. ต้นไม้ CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS DERIVATION TREE

36 Given a context-free grammar G with  = { a, + } andS  S + S | a The sentence a+a+a is in L(G) which has two derivations. S  S+S  a+S  a+S+S  a+a+S  a+a+a S  S+S  S+S+S  a+S+S  a+a+S  a+a+a This language is ambiguous. ความ กำกวม AMBIGUOUS ต้นไม้ CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS

37 น่าคิด โจทย์ น่าคิด ? Let G be a context-free and x  n G y be a derivation in G where x can be written x = y 1 A 1 y 2 A 2 …y k A k y k+1 with y i   *. Show that there are strings p i  (   V)* that satisfy 1. A i  ti p i. 2. y = y 1 p 1 y 2 p 2 …y k p k y k+1 3. Sum of all t i (1  i  k) = n.

38 Given a context-free grammar G with S  if E S | if E S else S | S This language is ambiguous. S if E S if E S else S statement2 exp1 statement1 exp2 S if E S if E S else S statement2 exp1 statement1 exp2 PARENTHESES CAN BE USED TO REMOVE THE AMBIGUITY ตัวอย่ าง CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS if exp1 if exp2 statement1 else statement2

39 Given a context-free grammar G with S  S + S| S  S | S | a This language is ambiguous. Theorem The context-free grammar G 1 with productions S  S + T | T T  T  F | F F  (S) | a is unambiguous. ตัวอย่ าง CONTEXT-FREE LANGUAGES ภาษาไม่พึงบริบท CONTEXT-FREE GRAMMARS

40 NORMAL FORMS

41 A mbiguity is one undesirable property of a context-free grammar that we might wish to Eliminate. In this section we discuss some more straightforward ways of “improving” a grammar without changing the resulting language. NORMAL FORMS วัตถุประสงค์

42 We try to eliminate “  -productions”, of the form A  , and unit productions,” in which one variable is simply replaced by another. REMARK : production   G  If there are no -productions, ||  ||. If there are no unit productions, if || = || then this step consists of replacing a variable by a single terminal. NORMAL FORMS วัตถุประสงค์

43 Let L be the length of the current string. Let T be the number of terminals of the current string. For any string x  Language, of length k, then L+T = 2k. That is the number of steps S  G x is at most 2k-1 steps. NORMAL FORMS วัตถุประสงค์ We try to eliminate “  -productions”, of the form A  , and unit productions,” in which one variable is simply replaced by another.

44 Given a context-free grammar G with productions S  ABCBCDA A  CD B  Cb C  a |  D  bD |  NORMAL FORMS ตัวอย่ าง CONTEXT-FREE LANGUAGES  -Production  -Production ELIMINATING THE  -PRODUCTION 1. Replacing ABCBCDA by A 1 BC 1 BC 2 DA 2 2. Create 32 productions S  A 1 BC 1 BC 2 DA 2 and the others with or without A 1, C 1, C 2, D and A AddingA CD | C | D B Cb | b C a D bD | b

45 CONTEXT-FREE LANGUAGES NORMAL FORMS นิยาม  -Production  -Production NULLABLE A nullable variable in a context-free grammar G = ( V, , S, P ) is defined as follows: 1. Any variable A for which P contains the production A   is nullable. 2. If A  B 1 B 2 …B n and B 1, B 2, …, B n are nullables, then A is also nullable. 3. No other variables in V are nullable. A is nullable if and only if A  * G 

46 N 0 = { A  V | P contains the production A  }; j = 0; Doj = j + 1; N j = N j-1  { A | P contains A  B that B  N j- 1 * } While N j  N j-1 ; N j is the set of all nullable variables. From the previous example, N 0 = { C, D } and N 1 = { A, C, D }. NORMAL FORMS CONTEXT-FREE LANGUAGES อัลกอริ ทึม  -Production  -Production Algorithm: FindNull

47 Given a CFG G=(V, ,S,P), construct a CFG G 1 =(V, ,S,P 1 ) without  -productions as follows: Initialize P 1 to be P. Find all nullable variables in V, using FindNull. For every A   in P, add to P 1 every production that can be obtained form this one by deleting from  or more the occurrences in  of nullable variables. Delete all  -production from P 1. Delete any duplicates. Delete productions of the from A  A. NORMAL FORMS CONTEXT-FREE LANGUAGES อัลกอริ ทึม  -Production  -Production Algorithm: RemoveNull

48 ตัวอย่ าง Given a context-free grammar G with productions S  ABC | ACB A  ACD | CD B  Cb C  a |  D  bD |  NORMAL FORMS CONTEXT-FREE LANGUAGES  -Production  -Production

49 ตัวอย่ าง NORMAL FORMS CONTEXT-FREE LANGUAGES  -Production  -Production Given a context-free grammar G with productions S  ABC | ACB A  ACD | CD B  Cb C  a |  D  bD | 

50 ตัวอย่ าง Given a context-free grammar G with productions S  ABC | ACB A  ACD | CD | AC | C B  Cb C  a |  D  bD | b NORMAL FORMS CONTEXT-FREE LANGUAGES  -Production  -Production

51 ตัวอย่ าง Given a context-free grammar G with productions S  ABC | ACB A  ACD | CD | AC | C B  Cb C  a |  D  bD | b NORMAL FORMS CONTEXT-FREE LANGUAGES  -Production  -Production

52 ตัวอย่ าง Given a context-free grammar G with productions S  ABC | ACB | AB A  ACD | CD | AC | C | AD | D | A |  B  Cb | b C  a D  bD | b NORMAL FORMS CONTEXT-FREE LANGUAGES  -Production  -Production

53 ตัวอย่ าง Given a context-free grammar G with productions S  ABC | ACB | AB A  ACD | CD | AC | C | AD | D | A |  B  Cb | b C  a D  bD | b NORMAL FORMS CONTEXT-FREE LANGUAGES  -Production  -Production

54 ตัวอย่ าง Given a context-free grammar G with productions S  ABC | ACB | AB | BC | CB | B A  ACD | CD | AC | C | AD | D | A B  Cb | b C  a D  bD | b NORMAL FORMS CONTEXT-FREE LANGUAGES  -Production  -Production

55 Let G = ( V, , S, P ) be a context-free grammar, and let G 1 = ( V, , S, P ) be a context-free grammar obtained from G by Algorithm RemoveNull. Then G 1 has no  -productions, and L(G 1 ) = L(G) – {  }. NORMAL FORMS CONTEXT-FREE LANGUAGES ทฤษฎี บท  -Production  -Production Context-free grammar

56 Unit productions We try to eliminate “unit productions”, of the form A  B, and A  G * B. Suppose that the context-free grammar G has no  -productions. CONTEXT-FREE LANGUAGES NORMAL FORMS นิยาม Unit -Production Unit -Production

57 An A-derivable variable in a context-free grammar G = ( V, , S, P ) is defined as follows: 1. Any variable B for which P contains the production A  B, then B is A- derivable. 2. If C is A-derivable, if C  B is in P, and if B  A, then B is A-derivable. 3. No other variables in V are A-derivable. B is A-derivable if and only if A  * G B. CONTEXT-FREE LANGUAGES NORMAL FORMS นิยาม Unit -Production Unit -Production

58 Algorithm RemoveUnit REMOVING THE UNIT PRODUCTIONS FROM A CFG. Given a CFG G=(V, ,S,P) without  -productions, construct a CFG G 1 =(V, ,S,P 1 ) having no unit productions as follows: Initialize P 1 to be P. For each A in V, find the set of all A-derivable variables. For every pair (A, B) such that B is A-derivable, and every non-unit production B  , add the production A   to P 1. Delete all unit productions from P 1. NORMAL FORMS

59 THEOREM Let G = ( V, , S, P ) be a context-free grammar with no  -productions, and let G 1 = ( V, , S, P ) be a context-free grammar obtained from G by Algorithm RemoveUnit. Then G 1 contains no unit productions, and L(G 1 ) = L(G). NORMAL FORMS

60 EXAMPLE Given a context-free grammar G without  -productions, and with productions S  S + T | T T  T  F | F F  (S) | a S-derivable = { T, F } T-derivable = { F } Productions in P 1 S  S + T | T | T  F | (S) | a T  T  F | F | (S) | a F  (S) | a NORMAL FORMS

61 CHOMSKY NORMAL FORM Eliminating specific types of productions, such as  -productions and unit productions, it may also be useful to impose restrictions on the form of the remaining productions. Several types of “Normal forms” have been introduced; we shall present one of them, the Chomsky normal form. NORMAL FORMS

62 CNF CHOMSKY NORMAL FORM Definition A context-free grammar G = ( V, , S, P ) is in Chomsky normal form if every production is of one of these two types: A  BC A  a where A, B and C are variables, and a is a terminal symbol. NORMAL FORMS

63 CNF CHOMSKY NORMAL FORM Construct a CFG in CNF Given context-free grammar G = ( V, , S, P ) Construct G 1 = ( V, , S, P 1 ) with no  -productions and with no unit productions. Construct G 2 = ( V 2, , S, P 2 ) with productions A  B 1 B 2 …B k, for k  2 A  a Replace A  B 1 B 2 …B k by A  B 1 X 1, X 1  B 2 X 2, …, X k-1  B k-1 B k NORMAL FORMS

64 EXAMPLE Given a context-free grammar G with productions S  ABC | ACB | AB | BC | CB | B A  ACD | CD | AC | C | AD | D | A B  Cb | b C  a D  bD | b S-derivable = { B } A-derivable = { C, D } B-derivable = C-derivable = D-derivable =  NORMAL FORMS

65 EXAMPLE Given a context-free grammar G with productions S  ABC | ACB | AB | BC | CB | Cb | b A  ACD | CD | AC | AD | a | bD | b B  Cb | b C  a D  bD | b S-derivable = { B } A-derivable = { C, D } B-derivable = C-derivable = D-derivable =  NORMAL FORMS

66 EXAMPLE Given a context-free grammar G with productions S  ABC | ACB | AB | BC | CB | Cb | b A  ACD | CD | AC | AD | a | bD | b B  Cb | b C  a D  bD | b X b  b X bc  BC X cb  CB X cd  CD NORMAL FORMS

67 EXAMPLE Given a context-free grammar G with productions S  ABC | ACB | AB | BC | CB | CX b | b A  ACD | CD | AC | AD | a | X b D | b B  CX b | b C  a D  X b D | b X b  b X bc  BC X cb  CB X cd  CD NORMAL FORMS

68 EXAMPLE Given a context-free grammar G with productions S  AX bc | AX cb | AB | BC | CB | CX b | b A  AX cd | CD | AC | AD | a | X b D | b B  CX b | b C  a D  X b D | b X b  b X bc  BC X cb  CB X cd  CD NORMAL FORMS

69 THEOREM For any G = ( V, , S, P ) be a context-free grammar, there is a G 1 = ( V 1, , S, P 1 ) be a context-free grammar in CNF so that L(G 1 ) = L(G) – {  }. NORMAL FORMS


ดาวน์โหลด ppt ไวยกรณ์ไม่พึง บริบท CONTEXT-FREE GRAMMARS. วัตถุประสงค์ A context-free grammar (CFG) is a simple recursive method of specifying grammar rules by which.

งานนำเสนอที่คล้ายกัน


Ads by Google