{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

module7-print - Module 7 Properties of context-free...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
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 don’t 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 isn’t 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 0 that generates exactly the same words as G (with the exception of ε ), where all rules of the grammar G 0 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
Background image of page 1

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

View Full Document Right Arrow Icon
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 There’s 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 ε . To show that any nullable variable A is found, we can do induction on k , the length of the deriva- tion A k ε .
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}