1 pushdown automata there are context-free languages that are not regular. finite automata cannot...

41
1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages.

Upload: frederica-marilyn-sparks

Post on 08-Jan-2018

231 views

Category:

Documents


1 download

DESCRIPTION

3 Finite Automata Control unit q 0 Input file yes/no

TRANSCRIPT

Page 1: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

1

Pushdown Automata

• There are context-free languages that are not regular.

• Finite automata cannot recognize all context-free languages.

Page 2: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

2

Pushdown Automata• {a, b}* is regular.

• {akbk | k is a constant} is regular.

• {anbn | n 0} is not regular.

Page 3: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

3

Finite Automata

Control unitq0

Input file

yes/no

Page 4: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

4

Pushdown Automata

Control unitq0

Input file

yes/no

Stack

Page 5: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

5

Non-deterministic Pushdown Automata (NPDA)

M = (Q, , , , q0, z, F)Q: finite set of internal states: finite set of symbols - input alphabet: finite set of symbols - stack alphabet: Q ({}) finite subsets of Q * transition functionq0 Q: initial statez : stack start symbolF Q: set of final states

Page 6: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

6

Non-deterministic Pushdown Automata (NPDA)

: Q ({}) finite subsets of Q *

stack top

stack top replacement

Page 7: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

7

Example(q1, a, b) = {(q2, cd), (q3, )}

b

dc

q1

q2

q3

Page 8: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

8

ExampleM = (Q, , , , q0, z, F)

Q = {q0, q1, q2, q3} (q0, a, 0) = {(q1, 10), (q3, )} = {a, b} (q0, , 0) = {(q3, )} = {0, 1} (q1, a, 1) = {(q1, 11)}z = 0 (q1, b, 1) = {(q2, )}F = {q3} (q2, b, 1) = {(q2, )}(q2, , 0) = {(q3, )}

Page 9: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

9

Instantaneous Description

(q, w, u)

current state unread part of stack contents

input string

Page 10: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

10

Instantaneous Description

move: (q1, aw, bx) (q2, w, yx)

iff (q2, y) (q1, a, b)

Page 11: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

11

Instantaneous Description

(q1, x, y) (q2, u, v)

(q1, x, y) (q2, u, v)

Page 12: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

12

Language accepted by NPDA

Let M = (Q, , , , q0, z, F) be an NPDA.

L(M) = {w * | (q0, w, z) (qf, , u), qf F, u

*}

Page 13: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

13

ExampleL = {w {a, b}* | na(w) = nb(w)}

M = (Q, , , , q0, z, F) ?

Page 14: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

14

ExampleL = {w {a, b}* | na(w) = nb(w)}

M = (Q, , , , q0, z, F)Q = {q0, qf} (q0, , z) = {(qf, z)} = {a, b} (q0, a, z) = {(q0, 0z)} = {0, 1, z} (q0, b, z) = {(q0, 1z)}F = {qf} (q0, a, 0) = {(q0, 00)}(q0, b, 0) = {(q0, )}(q0, a, 1) = {(q0, )}(q0, b, 1) = {(q0, 11)}

Page 15: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

15

ExampleL = {wwR | w {a, b}+}

M = (Q, , , , q0, z, F) ?

Page 16: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

16

ExampleL = {wwR | w {a, b}+}

M = (Q, , , , q0, z, F)Q = {q0, q1, q2} = {a, b} = {a, b, z} F = {q2} (q0, a, a) = {(q0, aa)} (q0, , a) = {(q1, a)}(q0, b, a) = {(q0, ba)} (q0, , b) = {(q1, b)}(q0, a, b) = {(q0, ab)}(q0, b, b) = {(q0, bb)} (q1, a, a) = {(q1, )}(q0, a, z) = {(q0, az)} (q1, b, b) = {(q1, )}(q0, b, z) = {(q0, bz)} (q1, , z) = {(q2, z)}

Page 17: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

17

NPDA and Context-Free Languages

Greibach NF

(q0, , z) = {(q1, Sz)}S aSA | a (q1, a, S) = {(q1, SA), (q0, )}A bB (q1, b, A) = {(q1, B)}B b (q1, b, B) = {(q1, )}(q1, , z) = {(q2, )}

Page 18: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

18

TheoremFor any context-free language L not containing , there exists an NPDA M such that L = L(M).

Page 19: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

19

TheoremProof: G = (V, T, S, P)M = ({q0, q1, qf}, T, V{z}, , q0, z, {qf}) z V

(q0, , z) = {(q1, Sz)}(q1, u) (q1, a, A) iff A au P(q1, , z) = {(qf, z)}

Page 20: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

20

Example Greibach NF

(q0, , z) = {(q1, Sz)}S aA (q1, a, S) = {(q1, A)}A aABC | bB | a (q1, a, A) = {(q1, ABC), (q1, )}(q1, b, A) = {(q1, B)}B b (q1, b, B) = {(q1, )}C c (q1, c, C) = {(q1, )}(q1, , z) = {(q2, )}

Page 21: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

21

Context-Free Grammars for NPDA

M = (Q, , , , q0, z, F)

G = (V, T, S, P)

L(G) = L(M)

Page 22: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

22

Context-Free Grammars for NPDA

M = (Q, , , , q0, z, F)

M^: Single final state Final state entered iff the stack is empty (qi, a, A) = {c1, c2, ..., cn}

ci = (qj, ) ci = (qj, BC)

Page 23: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

23

Context-Free Grammars for NPDA

(qi, a, A) = {(qj, ), ... } ?

Page 24: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

24

Context-Free Grammars for NPDA

(qi, a, A) = {(qj, ), ... } ?

At qi erase A and move to qj if receiving a

Page 25: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

25

Context-Free Grammars for NPDA

(qi, a, A) = {(qj, BC), ... } ?

Page 26: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

26

Context-Free Grammars for NPDA

(qi, a, A) = {(qj, BC), ... } ?

At qi erase A and move to qk if receiving a and

at qj erase BC and move to qk

Page 27: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

27

Context-Free Grammars for NPDA

(qi, a, A) = {(qj, BC), ... } ?

At qi erase A and move to qk if receiving a andat qj erase BC and move to qk

At qi erase A and move to qk if receiving a andat qj erase B and move to qm and

at qm erase C and move to qk

Page 28: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

28

Context-Free Grammars for NPDA

(qi, a, A) = {(qj, ), ... }

At qi erase A and move to qj if receiving a

(qiAqj) a

Page 29: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

29

Context-Free Grammars for NPDA

(qi, a, A) = {(qj, BC), ... }

At qi erase A and move to qk if receiving a andat qj erase B and move to qm and

at qm erase C and move to qk

(qiAqk) a(qjBqm)(qmCqk)

Page 30: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

30

Context-Free Grammars for NPDA

Start symbol: (q0zqf)

Page 31: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

31

ExampleM = (Q, , , , q0, z, F)

Q = {q0, q1, q2} = {a} = {A, z} F = {q2}

(q0, a, z) = {(q0, Az)}(q0, a, A) = {(q0, A)}(q0, b, A) = {(q1, )}(q1, , z) = {(q2, )}

Page 32: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

32

ExampleM = (Q, , , , q0, z, F)

Q = {q0, q1, q2 , q3} = {a} = {A, z} F = {q2}

(q0, a, z) = {(q0, Az)} (q0, a, z) = {(q0, Az)}(q0, a, A) = {(q0, A)} (q0, a, A) = {(q3, )}(q0, b, A) = {(q1, )} (q3, , z) = {(q3, Az)}(q1, , z) = {(q2, )} (q0, b, A) = {(q1, )} (q1, , z) = {(q2, )}

Page 33: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

33

ExampleM = (Q, , , , q0, z, F)

Q = {q0, q1, q2 , q3} = {a} = {A, z} F = {q2}

(q0, a, z) = {(q0, Az)}(q0, a, A) = {(q3, )} (q0Aq3) a(q3, , z) = {(q3, Az)}(q0, b, A) = {(q1, )} (q0Aq1) b(q1, , z) = {(q2, )} (q1zq2)

Page 34: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

34

ExampleM = (Q, , , , q0, z, F)

Q = {q0, q1, q2 , q3} = {a} = {A, z} F = {q2}

(q0, a, z) = {(q0, Az)} (q0zq0) ...(q0, a, A) = {(q3, )} (q0zq1) ...(q3, , z) = {(q3, Az)} (q0zq2) ...(q0, b, A) = {(q1, )} (q0zq3) ...(q1, , z) = {(q2, )}

Page 35: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

35

ExampleM = (Q, , , , q0, z, F)

Q = {q0, q1, q2 , q3} = {a} = {A, z} F = {q2}

(q0, a, z) = {(q0, Az)} (q0zq0) a(q0Aq0)(q0zq0) |(q0, a, A) = {(q3, )} a(q0Aq1)(q1zq0) |(q3, , z) = {(q3, Az)} a(q0Aq2)(q2zq0)(q0, b, A) = {(q1, )} a(q0Aq3)(q3zq0)(q1, , z) = {(q2, )} ...

Page 36: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

36

TheoremIf L = L(M) for some NPDA M, then L is a context-free language.

Page 37: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

37

TheoremProof: M = (Q, , , , q0, z, {qf}) G = (V, T, S, P)

T = V = {(qiAqj) | A } S = (q0zqf)P:(qiAqj) a iff (qj, ) (qi, a, A)(qiAqm) a(qiBqm)(qmCqj) iff (qj, BC) (qi, a, A)

Page 38: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

38

Deterministic Pushdown Automata

A DPDA is a pushdown automaton that never has a

choice in its move:1. (q, a, b) contains at most one element.2. if (q, , b) is not empty, then (q, a, b) must be empty

for every a .

Page 39: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

39

Deterministic Context-Free Language

A language L is said to be a DCFL iff there exists a

DPDA M such that L = L(M).

Page 40: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

40

ExampleM = (Q, , , , q0, z, F)

Q = {q0, q1, q2} (q0, a, 0) = {(q1, 10)} = {a, b} (q1, a, 1) = {(q1, 11)} = {0, 1} (q1, b, 1) = {(q2, )}z = 0 (q2, b, 1) = {(q2, )}F = {q0} (q2, , 0) = {(q0, )}

L = {anbn | n 0}

Page 41: 1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages

41

Homework• Exercises: 5, 10, 13 of Section 7.1 - Linz’s book.

• Exercises: 1, 2, 4, 5, 8, 12 of Section 7.2 - Linz’s book.

• Exercises: 1, 2, 3, 6, 7 of Section 7.2 - Linz’s book.

• Presentations: Section 6.3 and Section 7.4.