This preview shows pages 1–10. Sign up to view the full content.
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 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: 1 Normal Forms for CFGs Eliminating Useless Variables Removing Epsilon Removing Unit Productions Chomsky Normal Form 2 Variables That Derive Nothing Consider: S > AB, A > aA  a, B > AB Although A derives all strings of as, B derives no terminal strings (can you prove this fact?). Thus, S derives nothing, and the language is empty. 3 Testing Whether a Variable Derives Some Terminal String Basis : If there is a production A > w, where w has no variables, then A derives a terminal string. Induction : If there is a production A > , where consists only of terminals and variables known to derive a terminal string, then A derives a terminal string. 4 Testing (2) Eventually, we can find no more variables. An easy induction on the order in which variables are discovered shows that each one truly derives a terminal string. Conversely, any variable that derives a terminal string will be discovered by this algorithm. 5 Proof of Converse The proof is an induction on the height of the leastheight parse tree by which a variable A derives a terminal string. Basis : Height = 1. Tree looks like: Then the basis of the algorithm tells us that A will be discovered. A a 1 a n . . . 6 Induction for Converse Assume IH for parse trees of height < h, and suppose A derives a terminal string via a parse tree of height h: By IH, those X i s that are variables are discovered. Thus, A will also be discovered, because it has a right side of terminals and/or discovered variables. A X 1 X n . . . w 1 w n 7 Algorithm to Eliminate Variables That Derive Nothing 1. Discover all variables that derive terminal strings. 2. For all other variables, remove all productions in which they appear either on the left or the right. 8 Example : Eliminate Variables S > AB  C, A > aA  a, B > bB, C > c Basis : A and C are identified because of A > a and C > c. Induction : S is identified because of S > C. Nothing else can be identified. Result : S > C, A > aA  a, C > c 9 Unreachable Symbols Another way a terminal or variable deserves to be eliminated is if it cannot appear in any derivation from the start symbol....
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.
 Spring '08
 Motwani,R

Click to edit the document details