9 views

Uploaded by MELJUN CORTES, MBA,MPA

MELJUN CORTES -- AUTOMATA THEORY LECTURE

save

You are on page 1of 23

Andrej Bogdanov

http://www.cse.cuhk.edu.hk/~andrejb/csc3130

Pushdown automata

Fall 2008

MELJUN P. CORTES, MBA,MPA,BSCS,ACS

Motivation

• We had two ways to describe regular languages

• How about context-free languages?

regular

expression

DFA NFA

syntactic

computational

CFG pushdown automaton

syntactic

computational

Pushdown automata versus NFA

• Since context-free is more powerful than regular,

pushdown automata must generalize NFAs

state control

0 1 0 0

input

NFA

Pushdown automata

• A pushdown automaton has access to a stack,

which is a potentially infinite supply of memory

state control

0 1 0 0

input

pushdown automaton (PDA)

…

stack

Pushdown automata

• As the PDA is reading the input, it can push / pop

symbols in / out of the stack

state control

0 1 0 0

input

pushdown automaton (PDA)

Z

0

0 1

stack

…

1

Rules for pushdown automata

• The transitions are nondeterministic

• Stack is always accessed from the top

• Each transition can pop a symbol from the stack

and / or push another symbol onto the stack

• Transitions depend on input symbol and on last

symbol popped from stack

• Automaton accepts if after reading whole input, it

can reach an accepting state

Example

L = {0

n

#1

n

: n ≥ 0}

state control

0 0 0 #

input

Z

0

a a

stack

a

…

1 1 1

read 0

push a

read #

read 1

pop a

pop Z

0

Shorthand notation

read 0

push a

read #

read 1

pop a

pop Z

0

0, c / a

#, c / c

c, Z

0

/ c

1, a / c

read, pop / push

Formal definition

A pushdown automaton is (Q, E, I, o, q

0

, Z

0

, F):

– Q is a finite set of states;

– E is the input alphabet;

– I is the stack alphabet, including a special symbol Z

0

;

– q

0

in Q is the initial state;

– Z

0

in I is the start symbol;

– F _ Q is a set of final states;

– o is the transition function

o: Q × (E {c}) × (I {c}) subsets of Q × (I {c})

state input symbol pop symbol state push symbol

Notes on definition

• We use slightly different definition than textbook

• Example

0, c / a

#, c / c

c, Z

0

/ c

1, a / c

o: Q × (E {c}) × (I {c}) → subsets of Q × (I {c})

q

0

q

1

q

2

o(q

0

, 0, c) = {(q

0

, a)}

o(q

0

, 1, c) = ∅

o(q

0

, #, c) = {(q

1

, c)}

o(q

0

, 0, o) = ∅

...

A convention

• Sometimes we denote “transitions” by:

• This will mean:

– Intuitively, pop b, then push c

1

, c

2

, and c

3

a, b / c

1

c

2

c

3

q

0

q

1

c, c / c

2

q

0

q

1

a, b / c

1

c, c / c

3

intermediate

states

Examples

• Describe PDAs for the following languages:

– L = {w#w

R

: w {0, 1}*}, E = {0, 1, #}

– L = {ww

R

: w E*}, E = {0, 1}

– L = {w: w has same number of 0s and 1s}, E = {0, 1}

– L = {0

i

1

j

: i ≤ j ≤ 2i}, E = {0, 1}

Main theorem

A language L is context-free if and only if it

is accepted by some pushdown automaton.

context-free grammar pushdown automaton

From CFGs to PDAs

• Idea: Use PDA to simulate (rightmost) derivations

A → 0A1

A → B

B → #

A

¬ 0A1 ¬ 00A11 ¬ 00B11 ¬ 00#11

PDA control:

CFG:

write start variable

stack:

Z

0

A

replace production in reverse

Z

0

1A0

pop terminals and match Z

0

1A

e, e / A

0, 0 / e

e, A / 1A0

input:

00#11

00#11

0#11

replace production in reverse

Z

0

11A0 e, A / 1A0 0#11

pop terminals and match Z

0

11A 0, 0 / e #11

replace production in reverse

Z

0

11B e, A / B #11

From CFGs to PDAs

• If, after reading whole input, PDA ends up with an

empty stack, derivation must be valid

• Conversely, if there is no valid derivation, PDA

will get stuck somewhere

– Either unable to match next input symbol,

– Or match whole input but stack non empty

Description of PDA for CFGs

• Repeat the following steps:

– If the top of the stack is a variable A:

Choose a rule A → o and substitute A with o

– If the top of the stack is a terminal a:

Read next input symbol and compare to a

If they don’t match, reject (die)

– If top of stack is Z

0

, go to accept state

Description of PDA for CFGs

q

0

q

1

q

2

c, c / S

a, a / c

for every terminal a

c, A / o

k

...o

1

for every production A → o

1

...o

k

c, Z

0

/ c

From PDAs to CFGs

• First, we simplify the PDA:

– It has a single accept state q

f

– Z

0

is always popped exactly before accepting

– Each transition is either a push, or a pop, but not both

context-free grammar pushdown automaton

✓

From PDAs to CFGs

• We look at the stack in an accepting

computation:

a

Z

0

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

Z

0

b a c c c

a

portions that preserve the stack

q

0

q

1

q

3

q

1

q

7

q

0

q

1

q

2

q

1

q

3

q

7

A

03

= {x: x leads from q

0

to q

3

and preserves stack}

c

1 1

c

0 1

c c

0 0 0

input

state

stack

q

f

From PDAs to CFGs

a

Z

0

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

Z

0

b a c c c

a

q

0

q

1

q

3

q

1

q

7

q

1

q

2

q

1

q

7

c

1 1

c

0 1

c c

0 0 0

input

state

stack

A

11

A

03

0

c

A

11

→ 0A

03

c

q

0

q

3

q

f

From PDAs to CFGs

a

Z

0

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

a

Z

0

Z

0

b a c c c

a

q

0

q

1

q

3

q

1

q

7

q

1

q

2

q

1

q

7

c

1 1

c

0 1

c c

0 0 0

input

state

stack

A

03

A

13

A

13

→ A

10

A

03

q

0

q

3

A

10

q

f

From PDAs to CFGs

q

i

q

j

q

i’

q

j’

A

ij

→ aA

i’j’

b

q

i

q

j

q

k

A

ik

→ A

ij

A

jk

q

i

A

ii

→ c

variables:

A

ij

q

f

a, Z

0

/c

q

i

A

0f

→ A

0i

a

start variable:

A

0f

Example

0, c / a

#, c / c

c, Z

0

/ c

1, a / c

q

0

q

1

q

2

start variable: A

02

productions:

A

00

→ A

00

A

00

A

00

→ A

01

A

10

A

00

→ A

03

A

30

A

01

→ A

01

A

11

A

01

→ A

02

A

21

A

00

→ c

...

A

11

→ c

A

22

→ c

A

01

→ 0A

01

1

A

01

→ #A

33

A

33

→ c

0, c / a

#, c / $

c, Z

0

/ c

1, a / c

q

0

q

1

q

2

q

3

c, $ / c

A

02

→ A

01

- 030 Lexical AnalysisUploaded byyaswanthraj
- LA Editorial TSMCBUploaded byNida Ali
- MELJUN CORTES - AUTOMATA with SOLUTION and ANSWERUploaded byMELJUN CORTES, MBA,MPA
- MATHEMATICAL COMBINATORICS (INTERNATIONAL BOOK SERIES), Volume 2 / 2014Uploaded byAnonymous 0U9j6BLllB
- Lecture 02Uploaded byJohaira Lidasan
- PdaUploaded bySalitha
- MELJUN CORTES Automata Lecture Non-regular Languages 1Uploaded byMELJUN CORTES, MBA,MPA
- Regular Languages and Finite Automata - Marcelo FioreUploaded bySnow_Orb
- lect4_NFAUploaded bydeThirdKind
- acm (1)Uploaded byTawan Charoenphorn
- titletocUploaded byMahendra Singh Chouhan
- ds1Uploaded byshubhang2392
- FAFL Notes [2010] (SJBIT)Uploaded bymaruthinmdc
- Theory of Computation 123Uploaded byprabakaranbsc
- Theory IntroUploaded byapi-26825468
- Bai Tap Nang Cao Lop 7Uploaded bynguyenthieuhoa
- Inglesh FileUploaded byWitman Witman Campos Garay
- CFP-Craiova 2010[1]Uploaded byIvana D. Kostic
- Gnanaprabha Guess Paper 2017Uploaded byJayanth Samavedam
- Unit 14 TestUploaded byDavid Campoverde
- W. M. Lindsay, Syntax of Plautus (Summary)Uploaded byVerónica Díaz Pereyro
- Category Set TheoryUploaded bymars
- Eng Rev Gr2 Phonics and SpellingUploaded byezzeldin3khater
- Cricket LessonUploaded byMiron Simona
- Unit 1-Task 1. Stand Out BasicUploaded byJhon Martinez
- Bhasha Ke Liye Lekhan PadhatiUploaded byRIz
- february 1 2016Uploaded byapi-248290167
- Language and Woman 039 s PlaceUploaded byMB
- SO_I_U1_TestBUploaded byVane Perellón
- 1kid_s_box_1_teacher_s_book.pdfUploaded byAura Loredana Stefan

- MELJUN CORTES - MACHINE LEARNING Part 13Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - MACHINE LEARNING Part 2Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - MACHINE LEARNING Part 12Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - MACHINE LEARNING Part 3Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - MACHINE LEARNING Part 7Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - MACHINE LEARNING Part 5Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - MACHINE LEARNING Part 9Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - MACHINE LEARNING Part 6Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - MACHINE LEARNING Part 4Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - MACHINE LEARNING Part 7Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - MACHINE LEARNING Part 14Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES Research Paper 6 Metro South JULY 9 2018Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - MACHINE LEARNING Part 11Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - MACHINE LEARNING Part 1Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - MACHINE LEARNING Part 10Uploaded byMELJUN CORTES, MBA,MPA
- Meljun Cortes - Internet of Thing 3Uploaded byMELJUN CORTES, MBA,MPA
- Meljun Cortes - Internet of Thing 8Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU Final Exam Computer Application 2Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES ABSTRACT Research Paper 6 Metro South JULY 9 2018Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU Syllabus Cs 3113 Multimedia Animation Syllabus Cortes Obe New Formats New Revisions 2018Uploaded byMELJUN CORTES, MBA,MPA
- Meljun Cortes - Internet of Thing 4Uploaded byMELJUN CORTES, MBA,MPA
- Meljun Cortes - Internet of Thing 7Uploaded byMELJUN CORTES, MBA,MPA
- Meljun Cortes - Internet of Thing 1Uploaded byMELJUN CORTES, MBA,MPA
- Meljun Cortes - Internet of Thing 2Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU Syllabus Elec 5 Business Intelligence Syllabus Cortes Obe New Formats New Revisions 2018Uploaded byMELJUN CORTES, MBA,MPA
- Meljun Cortes - Internet of Thing 6Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES TCU Syllabus Ds 101 Discrete Structures 1 Syllabus Cortes Obe New Formats New Revisions 2018Uploaded byMELJUN CORTES, MBA,MPA
- Meljun Cortes - Internet of Thing 5Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - Machine Learning Algorithm 2Uploaded byMELJUN CORTES, MBA,MPA
- MELJUN CORTES - Machine Learning Algorithm 1Uploaded byMELJUN CORTES, MBA,MPA