# Context-free Languages

date post

24-Feb-2016Category

## Documents

view

27download

0

Embed Size (px)

description

### Transcript of Context-free Languages

PowerPoint Presentation

Context-free LanguagesChapter 2

Ambiguity

Chomsky normal form

Study Example 2.10 in the book

Pushdown Automata

PDA Example

PDA Example

What language is this?{w | w has exactly one more b than as where = {a, b}}12a, ab, ba, b b, a , b {w | w has exactly one more b than as where = {a, b}}12a, ab, ba, b b, a , b Dilemma 1: I am in State 1; The current input symbol is b and there is a b on the stack. What do you do?{w | w has exactly one more b than as where = {a, b}}12a, ab, ba, b b, a , b Dilemma 2: What if my input string is bbb?13a, ab, ba, b b, a , b Dilemma 2: What if my input string is bbb?20, $ , ${w | w has exactly one more b than as where = {a, b}}Possible Answer 1:S Sab | aSb | abS | Sba | bSa | baS | bHow do you create bbaaabb?

{w | w has exactly one more b than as where = {a, b}}Possible Answer 2:S SaSbS | SbSaS | b

What is the problem with this?

{w | w has exactly one more b than as where = {a, b}}Possible Answer 3:S XbX | XbX // one b surrounded by X

/* X can be empty or it must contain an equal number of as and bs */

X XaXbX | XbXaX |

/* We need ab and ba with Xs nested anywhere inbetween */Pumping Lemma for CFLCan prove that a language A is NOT context free, i.e., no PDA can accept and no CFG can generate.Pumping Lemma says:s = uvxyzFor each i >= 0, si = uvixyiz A|vy| > 0|vxy| = pp is the number of PDA transitions needed to visit the same state twice, i.e., take a loop

Consider this CFLA = {w | w has exactly one more b than as where = {a, b}}

s = ap bp+1s is clearly in AConsider p = 2, s.t., s = aabbb, which we know is a reasonably small p.The adversary can choose:u = a, v = a, x = , y = b, z = bb

si = uvixyiz A|vy| > 0|vxy| 03. vxy = ab, i.e., |vxy| >= 2

1. si = uvixyiz A for all i Every time we pump up v=a, we also pump up y=b.

si = uvixyiz A|vy| > 0|vxy| 0|vxy|