Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 16 Cocke-Younger-Kasimi Parsing Topics: Closure Properties of Context Free Languages Cocke-Younger-Kasimi Parsing Algorithm June 23, 2015 CSCE.

Similar presentations


Presentation on theme: "Lecture 16 Cocke-Younger-Kasimi Parsing Topics: Closure Properties of Context Free Languages Cocke-Younger-Kasimi Parsing Algorithm June 23, 2015 CSCE."— Presentation transcript:

1 Lecture 16 Cocke-Younger-Kasimi Parsing Topics: Closure Properties of Context Free Languages Cocke-Younger-Kasimi Parsing Algorithm June 23, 2015 CSCE 355 Foundations of Computation

2 – 2 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010 2 Summary of Decision Properties  As usual, when we talk about “a CFL” we really mean “a representation for the CFL, e.g., a CFG or a PDA accepting by final state or empty stack.  There are algorithms to decide if: 1. String w is in CFL L. 2. CFL L is empty. 3. CFL L is infinite.

3 – 3 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010 3 Non-Decision Properties  Many questions that can be decided for regular sets cannot be decided for CFL’s.  Example: Are two CFL’s the same?  Example: Are two CFL’s disjoint? How would you do that for regular languages?  Need theory of Turing machines and decidability to prove no algorithm exists.

4 – 4 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010 4 Testing Emptiness  We already did this.  We learned to eliminate variables that generate no terminal string.  If the start symbol is one of these, then the CFL is empty; otherwise not.

5 – 5 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010 5 Testing Membership  Want to know if string w is in L(G).  Assume G is in CNF. Or convert the given grammar to CNF. w = ε is a special case, solved by testing if the start symbol is nullable.  Algorithm (CYK ) is a good example of dynamic programming and runs in time O(n 3 ), where n = |w|.

6 – 6 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010 6 CYK Algorithm  Let w = a 1 …a n.  We construct an n-by-n triangular array of sets of variables.  X ij = {variables A | A =>* a i …a j }.  Induction on j–i+1. The length of the derived string.  Finally, ask if S is in X 1n.

7 – 7 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010 7 CYK Algorithm – (2)  Basis: X ii = {A | A -> a i is a production}.  Induction: X ij = {A | there is a production A -> BC and an integer k, with i BC and an integer k, with i < k < j, such that B is in X ik and C is in X k+1,j.

8 – 8 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010 8 Example: CYK Algorithm Grammar: S -> AB A -> BC | a B -> AC | b C -> a | b String w = ababa X 11 ={A,C} X 22 ={B,C} X 33 ={A,C} X 44 ={B,C} X 55 ={A,C} X 12 ={B,S}X 23 ={A} X 34 ={B,S} X 45 ={A}

9 – 9 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010 9 Example: CYK Algorithm X 11 ={A,C} X 22 ={B,C} X 33 ={A,C} X 44 ={B,C} X 55 ={A,C} X 12 ={B,S}X 23 ={A} X 34 ={B,S} X 45 ={A} X 13 ={} Yields nothing Grammar: S -> AB A -> BC | a B -> AC | b C -> a | b String w = ababa

10 – 10 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010 10 Example: CYK Algorithm X 11 ={A,C} X 22 ={B,C} X 33 ={A,C} X 44 ={B,C} X 55 ={A,C} X 12 ={B,S}X 23 ={A} X 34 ={B,S} X 45 ={A} X 13 ={A}X 24 ={B,S} X 35 ={A} Grammar: S -> AB A -> BC | a B -> AC | b C -> a | b String w = ababa

11 – 11 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010 11 Example: CYK Algorithm Grammar: S -> AB, A -> BC | a, B -> AC | b, C -> a | b String w = ababa X 11 ={A,C} X 22 ={B,C} X 33 ={A,C} X 44 ={B,C} X 55 ={A,C} X 12 ={B,S}X 23 ={A} X 34 ={B,S} X 45 ={A} X 13 ={A}X 24 ={B,S} X 35 ={A} X 14 ={B,S} Grammar: S -> AB A -> BC | a B -> AC | b C -> a | b String w = ababa

12 – 12 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010 12 Example: CYK Algorithm X 11 ={A,C} X 22 ={B,C} X 33 ={A,C} X 44 ={B,C} X 55 ={A,C} X 12 ={B,S}X 23 ={A} X 34 ={B,S} X 45 ={A} X 13 ={A}X 24 ={B,S} X 35 ={A} X 14 ={B,S}X 25 ={A} X 15 ={A} Grammar: S -> AB A -> BC | a B -> AC | b C -> a | b String w = ababa

13 – 13 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010

14 – 14 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010 4.4.3  Minimize  First distinguishes F = {C,F,I} and Q-F = {A,B,D,E,G,H} 01 AABE BCF *CDH DEH EFI *FGB GHB HIC *IAE

15 – 15 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010  On 0 does the partition refine Π 1 = {C, F, I}, {A, B, D, E, G, H} On 0 these map to D G A B C E F H I so  Π 2 = {C, F, I}, {A, D} {E, B, H} 01 AABE BCF *CDH DEH EFI *FGB GHB HIC *IAE

16 – 16 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010

17 – 17 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010

18 – 18 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010

19 – 19 – CSCE 355 Summer 2015 ialc slides Ullman Stanford 2010


Download ppt "Lecture 16 Cocke-Younger-Kasimi Parsing Topics: Closure Properties of Context Free Languages Cocke-Younger-Kasimi Parsing Algorithm June 23, 2015 CSCE."

Similar presentations


Ads by Google