Top Banner
1 A Non Context-Free Language (We will prove it at the next class)
49

A Non Context-Free Language

Jan 14, 2016

Download

Documents

amadis

A Non Context-Free Language. (We will prove it at the next class). Non Context-free languages. Context-free languages. Regular languages. Deterministic PDAs DPDAs. DPDAs. Allowed:. Not allowed:. Allowed:. Something must be matched from the stack. Not allowed:. DPDA example. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: A Non Context-Free Language

1

A Non Context-Free Language

(We will prove it at the next class)

Page 2: A Non Context-Free Language

2

Regular languages

**ba

Context-free languagesnnba

Non Context-free languagesnnn cba

Page 3: A Non Context-Free Language

3

Deterministic PDAs

DPDAs

Page 4: A Non Context-Free Language

4

DPDAs

Allowed: q1 q2wba ,

q1

q21, wba

q32, wca

Page 5: A Non Context-Free Language

5

q1

q21, wba

q32, wba

Not allowed:

Page 6: A Non Context-Free Language

6

Allowed:1q 2q

wb,

q1

q21, wb

q32, wc

Something must be matched from the stack

Page 7: A Non Context-Free Language

7

Not allowed:

q1

q21, wb

q32, wba

Page 8: A Non Context-Free Language

8

DPDA example

a, a

b, a q0 q1 q2 q3

b, a

, $ $

}0:{)( nbaML nn

a, a

Page 9: A Non Context-Free Language

9

}0:{)( nbaML nnThe language

is deterministic context-free

Page 10: A Non Context-Free Language

10

Definition:

A language is deterministic context-freeif some DPDA accepts it

Page 11: A Non Context-Free Language

11

Example of Non-DPDA (NPDA)

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

}{)( RwwML

Page 12: A Non Context-Free Language

12

, $ $q1 q2

bb

aa

,

,

, q0

bb

aa

,

,

Not allowed in DPDAs

Page 13: A Non Context-Free Language

13

NPDAs

Have More Power than

DPDAs

Page 14: A Non Context-Free Language

14

We will show:

there is a context-free language

which is not deterministic context-free

(accepted by a NPDA)

(not accepted by a DPDA)

L

Page 15: A Non Context-Free Language

15

The language is:

}{}{ 2nnnn babaL

0n

Page 16: A Non Context-Free Language

16

}{}{ 2nnnn babaL

The language is context-freeL

Context-free grammar for : L

21 | SSS

|11 baSS

|22 bbaSS

there is an NPDA that accepts L

Page 17: A Non Context-Free Language

17

}{}{ 2nnnn babaL

is not deterministic context-free

Theorem:

The language

(there is no DPDA that accepts ) L

Page 18: A Non Context-Free Language

18

Proof: Assume for contradiction that

}{}{ 2nnnn babaL

is deterministic context free

Therefore:

there is a DPDA that accepts M L

Page 19: A Non Context-Free Language

19

DPDA with M

nnba nb

acceptsnnba 2

acceptsnnba

}{}{)( 2nnnn babaML

Page 20: A Non Context-Free Language

20

The language is not context-free

}{ nnn cba

(we will prove it at the next class)

Fact 1:

Page 21: A Non Context-Free Language

21

The language is not context-free

}{ nnn cbaL

}){}{( 2nnnn babaL

(we will prove later today that the union oftwo context-free languages is context-free)

Fact 2:

Page 22: A Non Context-Free Language

22

We will construct a NPDA that accepts:

}{ nnn cbaL

}){}{( 2nnnn babaL

Contradiction!

Page 23: A Non Context-Free Language

23

We modify M

nc

Modified M

Replace with cb

nnca

}){}{( 2nnnn babaL

}){}{( 2nnnn cacaL

Page 24: A Non Context-Free Language

24

The NPDA that accepts }{ nnn cbaL

nnba nb

nc

Modified M

Original M

nnca

Page 25: A Non Context-Free Language

25

Since is accepted by a NPDA }{ nnn cbaL

it is context-free

Contradiction!

(since is not context-free)}{ nnn cbaL

Page 26: A Non Context-Free Language

26

Therefore:

}{}{ 2nnnn babaL

There is no DPDA that accepts

End of Proof

Not deterministic context free

Page 27: A Non Context-Free Language

27

Positive Propertiesof

Context-Free languages

Page 28: A Non Context-Free Language

28

Context-free languages are closed under: Union

1L is context free

2L is context free

21 LL

is context-free

Union

Page 29: A Non Context-Free Language

29

Example

|11 baSS

|| 222 bbSaaSS

Union

}{1nnbaL

}{2RwwL

21 | SSS }{}{ Rnn wwbaL

Language Grammar

Page 30: A Non Context-Free Language

30

In general:

The grammar of the union has new start variableand additional production 21 | SSS

For context-free languageswith context-free grammarsand start variables

21, LL

21, GG

21, SS

21 LL S

Page 31: A Non Context-Free Language

31

Context-free languages are closed under: Concatenation

1L is context free

2L is context free

21LL

is context-free

Concatenation

Page 32: A Non Context-Free Language

32

Example

|11 baSS

|| 222 bbSaaSS

Concatenation

}{1nnbaL

}{2RwwL

21SSS }}{{ Rnn wwbaL

Language Grammar

Page 33: A Non Context-Free Language

33

In general:

The grammar of the concatenation has new start variableand additional production 21SSS

For context-free languageswith context-free grammarsand start variables

21, LL

21, GG

21, SS

21LLS

Page 34: A Non Context-Free Language

34

Context-free languages are closed under: Star-operation

L is context free*L is context-free

Star Operation

Page 35: A Non Context-Free Language

35

|aSbS }{ nnbaL

|11 SSS *}{ nnbaL

Example

Language Grammar

Star Operation

Page 36: A Non Context-Free Language

36

In general:

The grammar of the star operation has new start variableand additional production

For context-free languagewith context-free grammarand start variable

LGS

*L1S

|11 SSS

Page 37: A Non Context-Free Language

37

Negative Propertiesof

Context-Free Languages

Page 38: A Non Context-Free Language

38

Context-free languagesare not closed under: intersection

1L is context free

2L is context free

21 LL

not necessarilycontext-free

Intersection

Page 39: A Non Context-Free Language

39

Example

}{1mnn cbaL

|

|

cCC

aAbA

ACS

Context-free:

}{2mmn cbaL

|

|

bBcB

aAA

ABS

Context-free:

}{21nnn cbaLL NOT context-free

Intersection

Page 40: A Non Context-Free Language

40

Context-free languagesare not closed under: complement

L is context free L not necessarilycontext-free

Complement

Page 41: A Non Context-Free Language

41

}{2121nnn cbaLLLL

NOT context-free

Example

}{1mnn cbaL

|

|

cCC

aAbA

ACS

Context-free:

}{2mmn cbaL

|

|

bBcB

aAA

ABS

Context-free:

Complement

Page 42: A Non Context-Free Language

42

Intersectionof

Context-free languagesand

Regular Languages

Page 43: A Non Context-Free Language

43

The intersection of a context-free language and a regular languageis a context-free language

1L context free

2L regular

21 LL

context-free

Page 44: A Non Context-Free Language

44

1Lfor for 2LNPDA

1M

DFA

2M

Construct a new NPDA machinethat accepts

Machine Machine

M21 LL

context-free regular

M simulates in parallel and 1M 2M

Page 45: A Non Context-Free Language

45

1M 2M

1q 2qcba ,

transition

1p 2pa

transition

NPDA DFA

11, pq cba ,

transition

MNPDA

22 , pq

Page 46: A Non Context-Free Language

46

1M 2M

0q

initial state

0p

initial state

NPDA DFA

Initial state

MNPDA

00 , pq

Page 47: A Non Context-Free Language

47

1M 2M

1q

final state

1p

final states

NPDA DFA

final states

MNPDA

11, pq

2p

21, pq

Page 48: A Non Context-Free Language

48

M simulates in parallel and 1M 2M

M accepts string w if and only if

accepts string and w1M

accepts string w2M

)()()( 21 MLMLML

Page 49: A Non Context-Free Language

49

Therefore: )()( 21 MLML

(since is NPDA) M

is context-free

21 LL is context-free