Title: Lecture 21 Properties of Context Free Languages
1Lecture 21Properties of Context Free Languages
CSCE 355 Foundations of Computation
- Topics
- Normal forms
- Closure properties
November 17, 2008
2- Last Time
- Test 2 not looked at
- Test 2 take-home
- New
- Equivalent Grammars, left factoring (review)
- Normal Forms for Grammars
- Useless symbols generating symbols, useful
symbols - Algorithm for generating and reachable symbols
- Epsilon productions unit productions
- Chomsky normal form
- Pumping Lemma for Context Free Languages
3Questions/Comments about Test 2?
4Homework
5Recall Equivalent Grammars?
6Left Factoring (recall)
7Useless Symbols
- A grammar symbol X is useful if
- S ? aXß ?w, where w is in T
- X is generating if
- X is reachable if
8Example 7.1
- S ? AB a
- A ? b
- Generating?
- Reachable?
- L(G)?
9Algorithm for Eliminating Useless Symbols
- Find non-generating symbols
- Eliminate all productions including
non-generating symbols - Eliminate non-reachable symbols
10Example from 7.1.1
- S ? AB CA
- A ? a
- B ? BC AB
- C ? aB b
- Generating?
- A?
- B?
- C?
- S?
- Reachable?
- Grammar after eliminating non-generating symbols
- Equivalent grammar with no useless symbols
11Theorem 7.2
12Proof of Theorem 7.2 -
- First show G1 has no useless symbols
- Generating?
- Reachable?
- L(G1) is a subset of L(G)
- L(G) is a subset of L(G1)
13Recursive (inductive) algorithms for 1)
generating symbols 2) reachable symbols
- Based on inductive definitions.
- Basis step.
- Inductive step.
14algorithm for generating symbols
15Theorem 7.4 Alg. finds Generating Symbols( and no
more)
16algorithm for reachable symbols
17Theorem 7.6 Alg. finds Reachable Symbols (and no
more)
18Nullable Symbols
19Algorithm for Nullable
20Eliminating Epsilon Productions
- Modify the grammar to produce and equivalent one
with no epsilon productions - Note which non-terminals are nullable
- Eliminate epsilon productions
- Then suppose B ? CAD where A is/was nullable
21More Generally
- Consider A ? X1 X2 Xk-1 Xk
- Suppose than M are nullable
- Then we add the 2m productions with all possible
subsets of the nullable non-terminals omitted - Exception if m k we dont allow all to be
eliminated
22Example
23Unit Productions
- E ? E T T
- Replace with
- E ? E T T F F
- But what if we have A ? B, B? C, C ? A
- Unit Pairs
24Unit Production removal
- Find unit pairs
- For each unit pair (A,B) add to P1 all reductions
of the form A? a, where B? a is a non-unit
production in P. - Note AB is possible
25Example 7.12
- E ? ET T
- T ? FT F
- F ? (E) I
26Chomsky Normal Form
27 28 29Pumping Lemma for CFLs
- Let L be a CFL. Then there exists a constant n
such that if z is a string in L of length at
least n, then we can write z uvwxy such that - vwx lt n
- vx gt 0
- uviwxi y is in L for all i gt 0.
30Similarities to Pumping Lemma for Regular
Languages
31Example L anbncn n gt 0
- Given L as above, suppose we chose n for the
Pumping Lemma (for CFLs). - Choose z
- Consider arbitrary partition of z uvwxy
satisfying - vwx lt n
- vx gt 0
- Then show
32Example