This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Module 7 Properties of context-free languages How porous are the boundaries of being context free? CS 360: Introduction to the Theory of Computing Daniel G. Brown, modified by Margareta Ackerman, University of Waterloo 7.1 Topics for this module Normal forms for context-free grammars The pumping lemma for context-free languages, and proving languages are not context free Closure properties for context-free languages Decision algorithms for context-free languages It is a somewhat surprising fact that context-free languages dont have all of the same closure prop- erties as regular languages. 7.2 1 Normal forms for context-free grammars Normal forms In this case, normal isnt a value statement, it more means that the grammar satisfies a very simple form. Theorem : For any context-free grammar G , there is a grammar G that generates exactly the same words as G (with the exception of ), where all rules of the grammar G are of one of the following two forms: A BC where A , B and C are variables A a , where A is a variable and a is a terminal Grammars in this form are in Chomsky Normal Form , or CNF. 7.3 Who cares? Who cares? Suppose we want to bound the number of production steps a word. This is very hard when derivations can be of arbitrary length! Also, can make ambiguity obvious (though not always). Idea : Each step: either number of terminals or string length increases at each step. All derivations for a word have the same length. 7.4 1 What has to be forbidden? We need to get rid of a bunch of kinds of forbidden rules: A B A ab A Ab A ABC A Some of these simplifications are easier than others, but none is especially hard. 7.5 First, removing rules A variable A in a grammar G is nullable if A * G . If the variable A is nullable, and there is a rule in the grammar B AC , then we could add a rule B C to the grammar, and the language of the grammar would not change. We previously would have had the derivation B AC * C ... Now, we just have the new derivation B C ... We can do this for any nullable variable. The only word lost from the language of the grammar is , if the start symbol for the grammar is nullable. 7.6 Identifying nullable variables Theres a simple rule for identifying nullable variables: If there exists a rule A , then A is nullable. If there exists a rule A B 1 B 2 ... B k , and all of the B i are nullable, then A is nullable. No other variables are nullable. Any variable found to be nullable by this method is certainly nullable, because the method gives the derivation of ....
View Full Document
This note was uploaded on 01/14/2012 for the course CS 360 taught by Professor Johnwatrous during the Winter '08 term at Waterloo.
- Winter '08