33
Deep Pushdown Deep Pushdown Automata Automata Alexander Meduna Alexander Meduna Brno University of Technology, Czech Republic [email protected] Based on Meduna, A.: Deep Pushdown Automata, Acta Informatica, 2006

Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic [email protected] Based on Meduna, A.: Deep Pushdown Automata,

Embed Size (px)

Citation preview

Page 1: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Deep Pushdown Deep Pushdown AutomataAutomata

Alexander MedunaAlexander Meduna

Brno University of Technology, Czech Republic

[email protected]

Based on

Meduna, A.: Deep Pushdown Automata, Acta Informatica, 2006

Page 2: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Pushdown Automaton (PDA)2/22

Am A1A2… ai an…a1 a2 …

Read-write headRead head

Pushdown: Input tape:

topmove of head

Finite State Control

p = current state

Page 3: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Inspiration

• conversion of CFG to PDA that acts as a general top-down parser

• if pd top = input symbol, pop• if pd top = non-input symbol, expand

3/22

Page 4: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

PDA as a general Top-Down Parser4/22

• Configuration: (state, input, pd)

• Pop: (q, ax, a) p (q, x, )

• Expansion: (q, x, A) e (p, x, )

by rule qA p

• Acceptance: (s, x, S) * (f, , )

Final state

Page 5: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Deep Pushdown Automata: Fundamental Modification

5/22

• expansion may be performed deeper in pd

Standard Expansion

top

#

A

B

b

C

Deep Expansion

qA px 3qC px

pq 3rd

#

A

B

b

C

x

x

Page 6: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Deep Pushdown Automata• Same as Top-Down Parser except deep expansions• Expansion of depth m:

• the mth topmost non-input pd symbol is replaced with a string by rule

6/22

depth of expansion

mqA px

states

pushdown stringpushdown symbol

Page 7: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Expansion of Depth m7/22

• Expansion of depth m: (q, w, uAz) e (p, w, uvz)

by rule of depth m [mqA pv],

where u contains m – 1 non-input symbols

Page 8: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Pop: Illustration8/22

Pushdown:

top

qp

#

a

A

b

B

c

Read headInput tape: move of head

cb ba a

a

Move: (p, aabbcc, aAbB#) p (p, abbcc, AbB#)

Page 9: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Pop: Illustration8/22

Pushdown:

top

qp

#

a

A

b

B

c

Read headInput tape: move of head

cb ba a

a =

Move: (p, aabbcc, aAbB#) p (p, abbcc, AbB#)

Page 10: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Pop: Illustration

pop

8/22

Pushdown:

top

qp

#

a

A

b

B

c

Read headInput tape: move of head

cb ba a

a =

Move: (p, aabbcc, aAbB#) p (p, abbcc, AbB#)

Page 11: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Pop: Illustration

pop

8/22

Pushdown:

top

qp

#

a

A

b

B

c

Read headInput tape: move of head

cb ba a

move head

Move: (p, aabbcc, aAbB#) p (p, abbcc, AbB#)

Page 12: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Pop: Illustration

pop

8/22

Pushdown:

top

qp

#

a

A

b

Bremove

Move: (p, aabbcc, aAbB#) p (p, abbcc, AbB#)

a c

Read headInput tape:

cb ba a

Page 13: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Pop: Illustration

pop

8/22

Pushdown:

top

qp

#

A

b

B

Move: (p, aabbcc, aAbB#) p (p, abbcc, AbB#)

a c

Read headInput tape:

cb ba a

Page 14: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Deep Expansion: Illustration9/22

a

Pushdown:

top

qp

#

A

b

B

c

Read headInput tape: move of head

cb ba a

A-

Rules

Move: (p, abbcc, AbB#) e (q, abbcc, AbBc#) [2pB qBc]

Page 15: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Deep Expansion: Illustration9/22

a

Pushdown:

top

qp

#

A

b

B

c

Read headInput tape: move of head

cb ba a

A-

Rules

Move: (p, abbcc, AbB#) e (q, abbcc, AbBc#) [2pB qBc]

2pB qBc

Page 16: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Deep Expansion: Illustration

expand

9/22

a

Pushdown:

top

qp

#

A

b

B

c

Read headInput tape: move of head

cb ba a

A-

Rules

Move: (p, abbcc, AbB#) e (q, abbcc, AbBc#) [2pB qBc]

2pB qBc

Page 17: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Deep Expansion: Illustration

expand

9/22

a

Pushdown:

top

qp

#

A

b

B

c

Read headInput tape: move of head

cb ba a

Rules expand

Move: (p, abbcc, AbB#) e (q, abbcc, AbBc#) [2pB qBc]

2pB qBc

Page 18: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Deep Expansion: Illustration

expand

9/22

a

Pushdown:

top

qp

#

A

b

B

c

Read headInput tape: move of head

cb ba a

Rules change state

Move: (p, abbcc, AbB#) e (q, abbcc, AbBc#) [2pB qBc]

2pB qBc

c

Page 19: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Deep Expansion: Illustration

expand

9/22

a

Pushdown:

top

qp

#

A

b

B

c

Read headInput tape: move of head

cb ba a

Rules change state

Move: (p, abbcc, AbB#) e (q, abbcc, AbBc#) [2pB qBc]

2pB qBc

c

Page 20: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Deep Expansion: Illustration

expand

9/22

a

Pushdown:

top

qp

#

A

b

B

c

Read headInput tape: move of head

cb ba a

Rules

Move: (p, abbcc, AbB#) e (q, abbcc, AbBc#) [2pB qBc]

2pB qBc

c

Page 21: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Example: Deep PDA

(s, aabbcc, S#)

e (q, aabbcc, AB#) [1]

e (p, aabbcc, aAbB#) [2]

p (p, abbcc, AbB#)

e (q, abbcc, AbBc#) [4]

e (f, abbcc, abbBc#) [3]

p (f, bbcc, bbBc#)

p2 (f, cc, Bc#)

e (f, cc, cc#) [5]

p (f, c, c#)

p (f, , #)

L(M) = {anbncn: n 1} PD2

Deep PDA M:

[1]. 1sS qAB[2]. 1qA paAb[3]. 1qA fab[4]. 2pB qBc[5]. 1fB fc

10/22

M accepts aabbcc:

Page 22: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Definition 1/3A deep pushdown automaton is a 7-tuple

M = (Q, , , R, s, S, F), where• Q – states,• – input alphabet, • – pushdown alphabet, bottom symbol # – • R – finite set of rules of the form

mqA pw or mq# pv#• s Q – start state• S – start pushdown symbol• F Q – final states

11/22

Page 23: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Definition 2/3

• if a non-input symbol is on pd top, M expands the pd as

(q, w, uAz) e (p, w, uvz) [mqA pv],

where u contains m – 1 non-input symbols

12/22

• if an input symbol is on pd top, M pops the pd as (q, au, az) p (q, u, z), a

• no explicit rule needed in R

Page 24: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Definition 3/3

• M is of depth n, denotated by nM, if n is the minimal positive integer such that each of M’s rules is of depth n or less.

13/22

• Language accepted by nM, L(nM), is defined as

L(nM) = {w *: (s, w, S#) * (f, , #) in nM

with f F}.

Page 25: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Main Result and its Proof

Theorem: PDn PDn+1, for all n 1.

• PDn – the language family defined by DeepPDAs of depth n.

14/22

Proof (Sketch):• State grammars (Kasai, 1970) are needed in the proof• State grammar is a modification of CFG based on rules of the form

(q, A) (p, v)

Page 26: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Proof 1/6: State Grammar15/22

• V – total alphabet, W – states, T V – terminals, • P – set of rules of the form (q, A) (p, v) • S (V – T) – start symbol,

• State grammar G = (V, W, T, P, S)

• Configuration – (q, x)

• Derivation step:

(q, uAz) (p, uvz) [(q, A) (p, v)]

and for every nonterminal B in u, P contains no rule with (q, B) on the left-hand side

Page 27: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Proof 2/6: n-limited Step16/22

• n-limited derivation step: each derivation step within the first n non-terminals

(q, uAz) n (p, uvz) and

uA has n or fewer non-terminals

• n-limited state language:

L(G, n) = {wT*:(q, S) n* (p, w)}

• STn – the family of n-limited state languages

Page 28: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Proof 3/6: Example

[1]. (1, S) (2, AC )[2]. (2, A) (3, aAb )[3]. (2, A) (4, ab )[4]. (3, C) (2, Cc )[5]. (4, C) (4, c )

W = {1, 2, 3, 4}

G generates aabbcc:

(S, 1) (AC, 2) [1] (aAbC, 3) [2] (aAbCc, 2) [4] (aabbCc, 4) [3] (aabbcc, 4) [5]

L(G) = {anbncn: n 1} ST2

State Grammar G:

17/22

Page 29: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Proof 4/6: PDn STn , n 118/22

• G simulates the application of ipA qy R:

• make a left-to-right scan of the pd until the ith

occurence of a non-terminal

• if Xi = A, then replace A with y and return to the beginning of the sentential form

• rightmost symbol is always a special a', and G completes the simulation by changing a' to a

Page 30: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Proof 5/6: STn PDn, n 119/22

• nM simulates G’s n-limited derivations in pd:

• always records the first n non-terminals from current G’s sentential form in its state

• fewer than n non-terminals are extended by #s

• reads the string, empties pd, enters $ F

Page 31: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Proof 6/6: PDn PDn+1, n 120/22

For all n 1, PDn = STn STn+1 = PDn+1

2) Kasai (1970): STn STn+1, for all n 1.

1) As PDn STn and STn PDn for all n 1, STn = PDn.

Q. E. D.

Page 32: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Note: PDn CS, n 121/22

For every n 1, there exists a context-sensitive language L not included in

PDn.

Page 33: Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  meduna@fit.vutbr.cz Based on Meduna, A.: Deep Pushdown Automata,

Open Problem Areas

• Determinism

• Rules of form mqA p

22/22

DiscussionDiscussion