npdas continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. formal definition....

69
1 … NPDAs continued

Upload: nguyenhuong

Post on 23-Apr-2018

231 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

1

… NPDAs continued

Page 2: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

2

Pushing Strings

q1 q2a, bw

Input

symbol

Pop

symbolPush

string

Page 3: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

3

q1 q2a, bcdf

a

b top

input

stack

a

Push

eh h

e

cdf

pushed

string

Example:

$ $

Page 4: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

4

Another NPDA example

$$, q1 q2

a, $0$

a, 000a,1

b, $1$

b,111b, 0

NPDA M

}:{)( ba nnwML

ryan
Callout
Linz 6th, Section 7.1, Example 7.4, page 187.
Page 5: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

5

Time 0

Input

a ab b b

current

state

a

$

Stack

$$, q1 q2

a, $0$

a, 000a,1

b, $1$

b,111b, 0

Execution Example:

Page 6: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

6

Time 1

Input

a ab b ba

$

Stack

0

$$, q1 q2

a, $0$

a, 000a,1

b, $1$

b,111b, 0

Page 7: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

7

Time 3

Input

a bb b a

$

Stack

a

$

$$, q1 q2

a, $0$

a, 000a,1

b, $1$

b,111b, 0

0

Page 8: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

8

Time 4

Input

a bb b a

$

Stack

a

1

$$, q1 q2

a, $0$

a, 000a,1

b, $1$

b,111b, 0

Page 9: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

9

Time 5

Input

a bb b a

$

Stack

a

1

1

$$, q1 q2

a, $0$

a, 000a,1

b, $1$

b,111b, 0

Page 10: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

10

Time 6

Input

a bb b a

$

Stack

a

1

$$, q1 q2

a, $0$

a, 000a,1

b, $1$

b,111b, 0

1

Page 11: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

11

Time 7

Input

a bb b a

$

Stack

a

1

$$, q1 q2

a, $0$

a, 000a,1

b, $1$

b,111b, 0

Page 12: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

12

Time 8

Input

a bb b a a

$

Stack

$$, q1 q2

a, $0$

a, 000a,1

b, $1$

b,111b, 0

accept

Page 13: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

13

Formalities for NPDAs

Page 14: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

14

q1 q2a, bw

)},{(),,( 21 wqbaq

Transition function:

Page 15: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

15

q1

q2wba ,

q3wba ,

)},(),,{(),,( 321 wqwqbaq

Transition function:

Page 16: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

16

Formal Definition

Non-Deterministic Pushdown Automaton

NPDA

),,,δ,Γ,Σ,( 0 FzqQM

States

Input

alphabetStack

alphabet

Transition

function

Final

states

Stack

start

symbolInitial

state

Page 17: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

17

Instantaneous Description

),,( suq

Current

state Remaining

input

Current

stack

contents

Page 18: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

18

a,a

b, aq0 q1 q2 q3

Input

Stack

a a a b b b

$

a

a

b, a

Time 4:

, , $$

Example: Instantaneous Description

$),,( 1 aaabbbq

a

Page 19: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

19

a,a

b, aq0 q1 q2 q3

Input

Stack

a a a b b b

$

a

a

b, a

Time 5:

, , $$

Example: Instantaneous Description

$),,( 2 aabbq

a

Page 20: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

20

We write:

$),,($),,( 21 aabbqaaabbbq

Time 4 Time 5

Page 21: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

21

a,a

b, aq0 q1 q2 q3

b, a

, , $$

,$),(,$),($),,($),,(

$),,($),,($),,(

,$),(,$),(

3222

111

10

qqabqaabbq

aaabbbqaaabbbqaaabbbq

aaabbbqaaabbbq

A computation:

Page 22: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

22

,$),(,$),($),,($),,(

$),,($),,($),,(

,$),(,$),(

3222

111

10

qqabqaabbq

aaabbbqaaabbbqaaabbbq

aaabbbqaaabbbq

For convenience we write:

,$),(,$),( 30 qaaabbbq

Page 23: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

23

Formal Definition

Language of NPDA :M

)}',,(),,(:{)( 0 sqswqwML f

Initial state Final state

Page 24: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

24

Example:,$),(,$),( 30 qaaabbbq

a,a

b, aq0 q1 q2 q3

b, a

, , $$

NPDA :M

)(MLaaabbb

Page 25: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

25

,$),(,$),( 30 qbaq nn

a,a

b, aq0 q1 q2 q3

b, a

, , $$

NPDA :M

)(MLba nn

Page 26: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

26

a,a

b, aq0 q1 q2 q3

b, a

, , $$

NPDA :M

}0:{)( nbaML nnTherefore:

Page 27: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

27

NPDAs Accept Context-Free Languages

Page 28: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

28

Context-Free

Languages

(Grammars)

Languages

Accepted by

NPDAs

Theorem:

Page 29: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

29

Context-Free

Languages

(Grammars)

Languages

Accepted by

NPDAs

Proof - Step 1:

Convert any context-free grammar

to a NPDA with:

GM )()( MLGL

Page 30: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

30

Context-Free

Languages

(Grammars)

Languages

Accepted by

NPDAs

Proof - Step 2:

Convert any NPDA to a context-free

grammar with: G

M)()( MLGL

Page 31: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

31

ConvertingContext-Free Grammars

to NPDAs

Page 32: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

32

An example grammar:

T

TaT

bS

aSTbS

What is the equivalent NPDA?

Page 33: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

33q0 q1 2q

S, , $$

Grammar:

NPDA:

T

TaT

bS

aSTbS

,

,

,

,

T

TaT

bS

aSTbS

bb

aa

,

,

Page 34: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

34

The NPDA simulates

leftmost derivations of the grammar

L(Grammar) = L(NPDA)

Page 35: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

35

Grammar:

T

TaT

bS

aSTbS

A leftmost derivation:

abababTababTbaSTbS

Page 36: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

36

NPDA execution:

0q q1 2qS, , $$

T

TaT

bS

aSTbS

,

,

,

,

bb

aa

,

,

Input

Stack

$

a ab

Time 0

b

current

state

Page 37: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

37q0 q1 2q

S, , $$

T

TaT

bS

aSTbS

,

,

,

,

bb

aa

,

,

Input

Stack

$

a ab

Time 1

b

S

Page 38: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

38q0 2q

S, , $$

T

TaT

bS

aSTbS

,

,

,

,

bb

aa

,

,

Input

Stack

$

a ab

Time 2

b

a

b

ST

q1

Page 39: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

39q0 2q

S, , $$

T

TaT

bS

aSTbS

,

,

,

,

bb

aa

,

,

Input

Stack

$

a ab

Time 3

b

a

b

ST

q1

Page 40: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

40q0 2q

S, , $$

T

TaT

bS

aSTbS

,

,

,

,

bb

aa

,

,

Input

Stack

$

a ab

Time 4

b

bTb

q1

Page 41: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

41q0 2q

S, , $$

T

TaT

bS

aSTbS

,

,

,

,

bb

aa

,

,

Input

Stack

$

a ab

Time 5

b

bTb

q1

Page 42: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

42q0 2q

S, , $$

T

TaT

bS

aSTbS

,

,

,

,

bb

aa

,

,

Input

Stack

$

a ab

Time 6

b

b

Ta

q1

Page 43: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

43q0 2q

S, , $$

T

TaT

bS

aSTbS

,

,

,

,

bb

aa

,

,

Input

Stack

$

a ab

Time 7

b

b

Ta

q1

Page 44: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

44q0 2q

S, , $$

T

TaT

bS

aSTbS

,

,

,

,

bb

aa

,

,

Input

Stack

$

a ab

Time 8

b

b

a

q1

Page 45: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

45q0 2q

S, , $$

T

TaT

bS

aSTbS

,

,

,

,

bb

aa

,

,

Input

Stack

$

a ab

Time 9

b

b

q1

Page 46: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

46q0 q1 2q

S, , $$

T

TaT

bS

aSTbS

,

,

,

,

bb

aa

,

,

Input

Stack

$

a ab

Time 10

b

accept

Page 47: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

47

In general:

Given any grammar G

We can construct a NPDA M

With )()( MLGL

Page 48: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

48

Constructing NPDA from grammar :

q0 q1 2qS, , $$

wA, aa,

M

For any production

wA

For any terminal

a

G

Page 49: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

49

Grammar generates string G w

if and only if

NPDA acceptsM w

)()( MLGL

Page 50: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

50

Therefore:

For any context-free language

there is an NPDA

that accepts the same language

Page 51: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

51

ConvertingNPDAs

toContext-Free Grammars

Page 52: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

52

For any NPDA M

we will construct

a context-free grammar withG

)()( GLML

Page 53: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

53

Intuition:

G

The grammar simulates the machine

A derivation in Grammar :

abcABCabcS

Current configuration in NPDA M

Page 54: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

54

in NPDA M

abcABCabcS

Input processed Stack contents

terminals variables

GA derivation in Grammar :

Page 55: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

55

Some Necessary Modifications

First, we modify the NPDA:

• It has a single final state

• It empties the stack

when it accepts the input

Original NPDA Empty Stack

fq

fq

Page 56: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

56

Second, we modify the NPDA transitions:

all transitions will have form

iq jqBa,

or

iq jqCDBa ,

symbolsstack :,, DCB

Page 57: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

57

$,0q fq

a, $0$

a, 000a,1

b, $1$

b,111b, 0

}:{)( ba nnwML

Example of a NPDA in correct form:

symbolstack initial :$

Page 58: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

58

The Grammar Construction

)( jiBqq

In grammar :G

Terminals:

Input symbols of NPDA

states

Stack symbol

Variables:

Page 59: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

59

iq jqBa,For each transition

We add production aBqq ji )(

Page 60: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

60

For each transition

We add production ))(()( klljki DqqCqqaBqq

iq jqCDBa ,

For all states lk qq ,

Page 61: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

61

Start Variable: )$( fo qq

Stack bottom symbol

Start state final state

Page 62: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

62

Example:

$,0q fq

a, $0$

a, 000a,1

b, $1$

b,111b, 0

aqq )1( 00Grammar production:

Page 63: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

63

Example:

$,0q fq

a, $0$

a, 000a,1

b, $1$

b,111b, 0

)$)(1(|)$)(1()$(

)$)(1(|)$)(1()$(

00000

00000000

fffff

ff

qqqqbqqqqbqq

qqqqbqqqqbqq

Grammar productions:

Page 64: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

64

Example:

$,0q fq

a, $0$

a, 000a,1

b, $1$

b,111b, 0

Grammar production: )$( 0 fqq

Page 65: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

65

)$)(1(|)$)(1()$(

)$)(1(|)$)(1()$(

00000

00000000

fffff

ff

qqqqbqqqqbqq

qqqqbqqqqbqq

)1)(1(|)1)(1()1(

)1)(1(|)1)(1()1(

00000

00000000

fffff

ff

qqqqbqqqqbqq

qqqqbqqqqbqq

)$)(0(|)$)(0()$(

)$)(0(|)$)(0()$(

00000

00000000

fffff

ff

qqqqaqqqqaqq

qqqqaqqqqaqq

Resulting Grammar: ablestart vari:)$( 0 fqq

Page 66: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

66

)0)(0(|)0)(0()0(

)0)(0(|)0)(0()0(

00000

00000000

fffff

ff

qqqqaqqqqaqq

qqqqaqqqqaqq

bqq

aqq

)0(

)1(

00

00

)$( 0 fqq

Page 67: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

67

Derivation of string abba

)$( 0 fqq )$)(0( 000 fqqqqa

)$( 0 fqqab

)$)(1( 000 fqqqqabb

)$( 0 fqqabba abba

Page 68: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

68

In general, in Grammar:

wqq f

)$( 0

if and only if

w is accepted by the NPDA

Page 69: NPDAs continued - cs.fit.eduryan/cse4083/busch/class11.pdf · 16. Formal Definition. Non-Deterministic Pushdown Automaton NPDA. M (Q , , + , / , q. 0, z , F ) States Input alphabet

69

Explanation:

By construction of Grammar:

wAqq ji

)(

if and only if

in the NPDA going from to

the stack doesn’t change below

and is removed from stack

iq jq

AA