Loading [MathJax]/jax/output/HTML-CSS/jax.js
Close
Close Window

OpenDSA Complete Catalog

Chapter 41 Parsing

| About   «  41.3. LR Parsing   ::   Contents   ::   41.5. Structure of a Compiler  »

41.4. CYK Parsing

41.4.1. CYK Parsing

Invented by J. Cocke, D.H. Younger, and T. Kasami

Requires |w|3 steps to parse string w.

Dynamic Programming remembers the answer to small subproblems so that it won’t have to solve them again.

For CYK Parsing, the grammar must be in Chomsky Normal Form (CNF) first.

Definition: A CFG is in Chomsky Normal Form (CNF) if all productions are of the form
ABC or Aa
where A,B,CV and aT.

41.4.1.1. CYK Parsing Algorithm

Assume G=(V,T,S,P) is in CNF, and w=a1a2...an.
Define substrings wij=ai...aj.
Define subsets of V,Vij={AVAwij}
Then wL(G) if and only if SV1n.

Note

AVii if and only if there is what kind of production?

Answer: Aai

All Vii are easy, just based on if there is a production.
Note: Compute Vij. For j>i, A derives wij if and only if there is a production ABC with Bwik and Cwk+1j for some k with ik,k<j.

41.4.1.2. Algorithm

  1. Compute V11,V22,V33,,Vnn

  2. Compute V12,V23,V34,,Vn1n

  3. Compute V13,V24,V35,,Vn2n

  4. Last step is? Compute V1n

How do we know if it worked? If the last step is S

   «  41.3. LR Parsing   ::   Contents   ::   41.5. Structure of a Compiler  »

Close Window