Transcript
  • 1

    CS 301 - Lecture 16 Pumping Lemma for

    Context Free Grammars Fall 2008

    Review •  Languages and Grammars

    –  Alphabets, strings, languages •  Regular Languages

    –  Deterministic Finite and Nondeterministic Automata –  Equivalence of NFA and DFA and Minimizing a DFA –  Regular Expressions –  Regular Grammars –  Properties of Regular Languages –  Languages that are not regular and the pumping lemma

    •  Context Free Languages –  Context Free Grammars –  Derivations: leftmost, rightmost and derivation trees –  Parsing and ambiguity –  Simplifications and Normal Forms –  Nondeterministic Pushdown Automata –  Pushdown Automata and Context Free Grammars –  Deterministic Pushdown Automata

    •  Today: –  Pumping Lemma for context free grammars

    The Pumping Lemma for

    Context-Free Languages

    Take an infinite context-free language

    Example:

    bBSbBaBbAABS

    Generates an infinite number of different strings

  • 2

    abbabbbbabbabbBbabbaBbBbabbABbabbSb

    abbBaBbBABS

    ⇒⇒

    ⇒⇒⇒⇒

    ⇒⇒⇒

    bBSbBaBbAABS

    A derivation:

    In a derivation of a long string, variables are repeated

    S

    A B

    bBa

    b

    bS

    A B

    bBa

    b

    b

    Derivation tree string abbabbbb

    S

    A B

    bBa

    b

    bS

    A B

    bBa

    b

    b

    repeated

    Derivation tree string abbabbbb B

    bS

    A B

    bBa

    b

    b

    aBbbbaBbBbABbSbB⇒⇒

    ⇒⇒⇒

    bB⇒aBbbbB*⇒

  • 3

    B

    bS

    A B

    bBa b

    Repeated Part

    aBbbbB*⇒

    B

    bS

    A B

    ba bB

    bS

    A B

    bBa b

    aaBbbbbbbaBbbbB**⇒⇒

    Another possible derivation from

    aBbbbB*⇒

    B

    B

    bS

    A B

    ba bB

    bS

    A B

    bBa b

    22** )()()()( bbbBabbbBaB ⇒⇒

    aBbbbB*⇒

    22* )()( bbbbaabbS⇒

    )()()( 22 GLbbbbaabb ∈

    aBbbbB*⇒ bB⇒abbBbS

    *⇒

  • 4

    S

    A B

    bBa

    baBbbbB*⇒

    bB⇒

    abbBbS*⇒

    abbbbabbBbS ⇒⇒*

    b

    00 )()( bbbbaabb=

    00* )()( bbbbaabbS⇒

    )()()( 00 GLbbbbaabb ∈

    aBbbbB*⇒ bB⇒abbBbS

    *⇒

    3333* )()()()( bbbbaabbbbbBaabbS ⇒⇒

    S

    A B

    bBa

    b

    bS

    A B

    ba bB

    bS

    A B

    bBa b

    bS

    A B

    bBa b

    b

    aBbbbB*⇒

    bB⇒

    abbBbS*⇒

    33* )()( bbbbaabbS⇒

    )()()( 33 GLbbbbaabb ∈

    aBbbbB*⇒ bB⇒abbBbS

    *⇒

  • 5

    ii bbbbaabbS )()(*⇒

    )()()( GLbbbbaabb ii ∈

    aBbbbB*⇒ bB⇒abbBbS

    *⇒

    In General:

    0≥i

    Consider now an infinite context-free language

    G

    Take so that I has no unit-productions no -productions

    L

    Let be the grammar of }{λ−L

    (Number of productions) x (Largest right side of a production)

    = Let

    bBSbBaBbAABS

    →Example :

    131=+= pm

    G

    p

    Let 1+= pm

    1234 =×=p

    Take a string with length

    )(GLw∈mw ≥||

    We will show: in the derivation of a variable of is repeated

    wG

  • 6

    wvvv k ⇒⇒⇒⇒ 21

    wS*⇒

    1vS =

    wvvv k ⇒⇒⇒⇒ 21

    fvv ii +< + |||| 1 maximum right hand side of any production

    fkw ⋅

    Number of productions in grammar

    >k

    Some production must be repeated

    wvvv k ⇒⇒⇒⇒ 21

    2

    2

    1

    rBrArS

    Repeated variable

    wAaaAaav ⇒⇒⇒⇒⇒⇒ 43211

  • 7

    )(GLw∈ mw ≥||

    wAaaAaaS ⇒⇒⇒⇒⇒⇒ 4321

    Some variable is repeated

    Derivation of string wS

    A

    A

    x

    Last repeated variable u z

    v yuvxyzw =:,,,, zyxvu

    repeated

    Strings of terminals

    Derivation tree of string w

    S

    A

    A

    x

    u z

    v y

    uAzS∗⇒

    vAyA∗⇒

    xA∗⇒

    Possible derivations:

    uAzS∗⇒ vAyA

    ∗⇒ xA

    ∗⇒

    We know:

    This string is also generated:

    uxzuAzS*⇒⇒

    zxyuv 00

  • 8

    This string is also generated:

    uvxyzuvAyzuAzS**⇒⇒⇒

    The original zxyuvw 11=

    uAzS∗⇒ vAyA

    ∗⇒ xA

    ∗⇒

    We know:

    This string is also generated:

    uvvxyyzuvvAyyzuvAyzuAzS***⇒⇒⇒⇒

    zxyuv 22

    uAzS∗⇒ vAyA

    ∗⇒ xA

    ∗⇒

    We know:

    This string is also generated:

    uvvvxyyyzuvvvAyyyz

    uvvAyyzuvAyzuAzS**

    **

    ⇒⇒

    ⇒⇒⇒⇒∗

    zxyuv 33

    uAzS∗⇒ vAyA

    ∗⇒ xA

    ∗⇒

    We know:

    This string is also generated:

    yyyzvxyuvvvyyyzvAyuvvv

    uvvvAyyyzuvvAyyzuvAyzuAzS

    ⇒⇒

    ⇒⇒

    ⇒⇒⇒⇒

    zxyuv ii

    uAzS∗⇒ vAyA

    ∗⇒ xA

    ∗⇒

    We know:

    *

    ***

    *****

  • 9

    Therefore, any string of the form

    zxyuv ii

    is generated by the grammar G

    0≥i

    knowing that )(GLuvxyz ∈

    we also know that )(GLzxyuv ii ∈

    Therefore,

    Lzxyuv ii ∈

    }{)( λ−= LGL

    S

    A

    A

    x

    u z

    v y

    mvxy ≤||Observation: Since is the last repeated variable A

    S

    A

    A

    x

    u z

    v y

    1|| ≥vyObservation: Since there are no unit or -productions λ

  • 10

    The Pumping Lemma:

    there exists an integer such that m

    for any string mwLw ≥∈ || ,

    we can write

    For infinite context-free language L

    uvxyzw =

    with lengths 1||and || ≥≤ vymvxy

    and it must be:

    0 allfor , ≥∈ iLzxyuv ii

    What’s Next •  Read

    –  Linz Chapter 1,2.1, 2.2, 2.3, (skip 2.4), 3, 4, 5, 6.1, 6.2, (skip 6.3), 7.1, 7.2, 7.3, (skip 7.4), and 8.1

    –  JFLAP Chapter 1, 2.1, (skip 2.2), 3, 4, 5, 6, 7 •  Next Lecture Topics

    –  More Pumping Lemma for Context Free Grammars •  Quiz 3 in Recitation on Wednesday 11/12

    –  Covers Linz 7.1, 7.2, 7.3, (skip 7.4), 8, and JFLAP 5,6,7 –  Closed book, but you may bring one sheet of 8.5 x 11 inch paper with any notes you

    like. –  Quiz will take the full hour

    •  Homework –  No homework today –  New Homework Available Friday Morning –  New Homework Due Next Thursday


Recommended