Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for...

Preview:

Citation preview

Lecture Note of 12/22

jinnjy

Outline

Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free

Languages Closure Properties of CFL

Chomsky Normal Form

A CFG is in Chomsky normal form if every form is of the form

A BC A a

Notice that we permit the rule S,where S is the start variable

Convert a CFG to an equivalent one in Chomsky Normal Form

1. Add a new start variable

2. Eliminate all rules of the form A .3. Eliminate all unit rules of the form AB.

4. Convert the remaining rules into the proper form.

Sipser’s method.

Convert a CFG to an equivalent one in Chomsky Normal Form (Cont’d)

1. Add a new start variable (optional)

2. Eliminate all rules of the form A .3. Eliminate all unit rules of the form AB.

4. Eliminate useless symbol

5. Convert the remaining rules into the proper form.

Method used in handout.

Convert a CFG to an equivalent one in Chomsky Normal Form (Cont’d) Why not eliminate all unit rules before eliminati

ng all rules? Ans: Unit rules may appear again after all rules are

eliminated.

Ex: 2.15

A BAB | B |

B00 |

Add new start symbol S. And after all unit rules eliminated:

SBAB | 00 |

A BAB | 00 |

B00 |

After all rules eliminated (S) is permitted:

S BAB | 00 | | BA | AB | A | BB | B

A BAB | 00 | BA | AB | A | BB | B

B00

AB appear again!!

Eliminate Useless Symbols We say a symbol X is generating if X can deriv

e some terminal string w, in zero or more steps. EX: Consider

S BC | BB | | 1

BSS

CBD

D is not generating, it can’t derive any terminal string.

C is also non-generating, since it can only change to BD

Algorithm used to Eliminate Nongenerating Symbols Basis: If X is a terminal , X is generating. Induction: Assume there is a production X,

and every symbol appear in is already known to be generating, then A is generating.

Eliminate Useless Symbols We say a variable X is reachable if S can deriv

e some string X, for some and . EX: Consider

S BB | | 1

BSS

DSB

D is not reachable from S.

Algorithm used to Eliminate Nonreachable Symbols Basis: The start symbol S is reachable. Induction: If variable A is reachable, then all sy

mbols appears in the rules of the form A is reachable.

CYK Algorithm Purpose: Decide whether a string w is in a CFL L, assume

we have a CFG G in Chomsky Normal Form s.t. L(G)=L. Fact: w is in L iff there exists terminal strings x, y s.t. w=xy

and there exists a rule S AB s.t. A can derive x and B can derive y.

CYK Algorithm Triangular table construction:

X1,n

X1,n-1

X1,2

X1,1

X2,n

X2,2

… …

Xn-1,n

… Xn,n

D=“On input w=a1a2…an (page 241)1.If w= and S→ is a rule, accept2.For i=1 to n3 For each variable A

4 Test whether A→b is a rule, where b=wi

5 if so, place A in Xii

6.For l=2 to n7. For i=1 to n-l+18. j=i+l-19. For k=i to j-110. For each rule A→BC

11. If Xi, k contains B and

Xk+1, j contains C

Put A in Xi, j

12.If S is in X1,n, ACCEPT;otherwise Reject. “

Closure Properties of CFL

CFL is closed under: Union Concatenation Kleene closure(*), and positive closure(+) Homomorphism Reversal

Substitution Substitiution:

Generalization of homomorphism Extensions: ( )

( ) ( ) ( )

( ) { ( )}w L

s

s xa s x s a

s L s w

* * **: 2 2 2s or

CFL is Closed Under Reversal Proof:

Assume L is a CFL with a CFG G=(V,T,P,S) We construct the CFG (V,T,PR,S)for LR:

V,T,S are the same as G For all rules A in P, PR contains the corresponding rul

e: AR

Decision Properties of CFL The following properties are decidable

Emptiness (Is L empty?) Membership (w in L?) Finite/ Infinite (Is L finite?)

Decision Properties of CFL The following properties are undecidable

Ambiguity (Is grammar G ambiguous?) Equivalence (L1 = L2?)

Empty Intersection (L1L2 =?) * equivalence (L=* ?) Inherently Ambiguity (Is L ambiguity ambiguous?)

Recommended