Lecture 21 Properties of Context Free Languages - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

Lecture 21 Properties of Context Free Languages

Description:

CSCE 355 Foundations of Computation. Last Time: Test 2 not looked at ... Equivalent Grammars, left factoring (review) Normal ... Xk-1 Xk. Suppose than ... – PowerPoint PPT presentation

Number of Views:110
Avg rating:3.0/5.0
Slides: 33
Provided by: mantonm5
Category:

less

Transcript and Presenter's Notes

Title: Lecture 21 Properties of Context Free Languages


1
Lecture 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

3
Questions/Comments about Test 2?
4
Homework
  • 7.1.1
  • 7.1.2
  • 7.1.3
  • 7.1.6

5
Recall Equivalent Grammars?
6
Left Factoring (recall)
7
Useless Symbols
  • A grammar symbol X is useful if
  • S ? aXß ?w, where w is in T
  • X is generating if
  • X is reachable if

8
Example 7.1
  • S ? AB a
  • A ? b
  • Generating?
  • Reachable?
  • L(G)?

9
Algorithm for Eliminating Useless Symbols
  1. Find non-generating symbols
  2. Eliminate all productions including
    non-generating symbols
  3. Eliminate non-reachable symbols

10
Example 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

11
Theorem 7.2
12
Proof 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)

13
Recursive (inductive) algorithms for 1)
generating symbols 2) reachable symbols
  • Based on inductive definitions.
  • Basis step.
  • Inductive step.

14
algorithm for generating symbols
15
Theorem 7.4 Alg. finds Generating Symbols( and no
more)
16
algorithm for reachable symbols
17
Theorem 7.6 Alg. finds Reachable Symbols (and no
more)
18
Nullable Symbols
19
Algorithm for Nullable
20
Eliminating 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

21
More 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

22
Example
23
Unit 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

24
Unit 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

25
Example 7.12
  • E ? ET T
  • T ? FT F
  • F ? (E) I

26
Chomsky Normal Form
27

28

29
Pumping 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.

30
Similarities to Pumping Lemma for Regular
Languages
31
Example 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

32
Example
Write a Comment
User Comments (0)
About PowerShow.com