lect14-cfl5

# lect14-cfl5 - 1 Properties of Context-Free Languages...

This preview shows pages 1–11. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Properties of Context-Free Languages Decision Properties Closure Properties 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 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 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 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 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 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 < k < j, such that B is in X ik and C is in X k+1,j . 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 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 ={} Yields nothing 10 Example : CYK Algorithm Grammar: S -> AB, A -> BC | a, B -> AC | b, C -> a | b...
View Full Document

## This note was uploaded on 03/30/2012 for the course CS 154 taught by Professor Motwani,r during the Spring '08 term at Stanford.

### Page1 / 35

lect14-cfl5 - 1 Properties of Context-Free Languages...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online