This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Chapter 4 Normal Forms for CFGs 2 4.5 Chomsky Normal Form ■ Defn 4.4.1 A CFG G = ( V , ∑ , P , S ) is in chomsky normal form if each rule in G has one of the following forms: i) A → BC ii) A → a iii) S → λ where A , B , C ∈ V and B , C ∈ V  { S } and a ∈ ∑ ■ A simplified normal form which restricts the length & composition of the R.H.S. of a rule in CFG ■ The derivation tree for a string generated by a CFG in chomsky normal form is a binary tree 3 4.5 Chomsky Normal Form ■ Theorem 4.4.2 Let G = ( V , ∑ , P , S ) be a CFG. There is an algorithm to construct a grammar G ’ = ( V ’, ∑ ’, P ’, S ’) in chomsky normal form that is equivalent to G Proof (sketch) : (i) For each rule A → w , where  w  > 1, replace each terminal a in w by a distinct variable Y & create new rule Y → a (ii) For each modified rule X → w ’, w is either a terminal or a string in V + . Rules in the latter form must be broken into a sequence of rules, each of whose R.H.S. consists of two variables. ■ Example 4.4.1 ■ One of the applications of using CFGs that are in Chomsky Normal Form Constructing binary search trees to accomplish “optimal” time & space search complexity for parsing an input string 4 4.1 Grammar Transformations ■ Lemma 4.1.1 Let G = ( V , ∑ , P , S ) be a CFG. There is a CFG G’ = ( V ’, ∑ , P ’, S ’) that satisfies i) L( G ) = L( G ’) ii) Rules in P ’ are of the form A → w where A ∈ V ’ and w ∈ (( V – { S ’}) ∪ ∑ )*. Proof . If S is a recursive variable , then construct G’ by creating a new start symbol S ’ & adding S’ → S to P ’, i.e., G’ = ( V ∪ { S ’} , ∑ , P ∪ { S’ → S } , S ’). If S u , then S ’ S u , where u ∈ ∑ *. Example. 4.1.1 Assume that P in G includes S → a S  AB  AC , then P ’ in G ’ should include S ’ → S, S → a S  AB  AC ⇒ G * ⇒ G’ ⇒ G’ * 5 4.2 Elimination of λrules ■ Nullable variables are variables that can derive λ ....
View
Full
Document
This note was uploaded on 03/02/2012 for the course C S 252 taught by Professor Dennisng during the Winter '12 term at BYU.
 Winter '12
 DennisNg

Click to edit the document details