Upcoming SlideShare
×

# MELJUN CORTES Automata Theory (Automata10)

274 views

Published on

MELJUN CORTES Automata Theory (Automata10)

Published in: Technology
1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
274
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
44
0
Likes
1
Embeds 0
No embeds

No notes for slide

### MELJUN CORTES Automata Theory (Automata10)

1. 1. MELJUN P. CORTES, MBA,MPA,BSCS,ACS Fall 2008 CSC 3130: Automata theory and formal languages Pushdown automata MELJUN CORTES
2. 2. Motivation • We had two ways to describe regular languages regular expression syntactic NFA DFA computational • How about context-free languages? CFG pushdown automaton syntactic computational
3. 3. Pushdown automata versus NFA • Since context-free is more powerful than regular, pushdown automata must generalize NFAs state control input 0 NFA 1 0 0
4. 4. Pushdown automata • A pushdown automaton has access to a stack, which is a potentially infinite supply of memory state control input 0 1 0 0 … stack pushdown automaton (PDA)
5. 5. Pushdown automata • As the PDA is reading the input, it can push / pop symbols in / out of the stack state control input 0 1 0 0 1 stack 1 Z0 0 pushdown automaton (PDA) …
6. 6. 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
7. 7. Example state control read 0 push a read # read 1 pop a pop Z0 L = {0n#1n: n ≥ 0} input 0 0 a stack Z0 0 # 1 1 a … a 1
8. 8. Shorthand notation read 0 push a 0, ε / a #, ε / ε read # read 1 pop a 1, a / ε ε, Z0 / ε pop Z0 read, pop / push
9. 9. Formal definition A pushdown automaton is (Q, Σ, Γ, δ, q0, Z0, F): – Q is a finite set of states; Σ is the input alphabet; Γ is the stack alphabet, including a special symbol Z0; – q0 in Q is the initial state; – Z0 in Γ is the start symbol; – F ⊆ Q is a set of final states; δ is the transition function δ: Q × (Σ ∪ {ε}) × (Γ ∪ {ε}) →subsets of Q × (Γ ∪ {ε}) state input symbol pop symbol state push symbol
10. 10. Notes on definition • We use slightly different definition than textbook • Example 0, ε / a 1, a / ε q0 q1 #, ε / ε ε, Z0 / ε q2 δ(q0, 0, ε) = {(q0, a)} δ(q0, 1, ε) = ∅ δ(q0, #, ε) = {(q1, ε)} δ(q0, 0, α) = ∅ ... δ: Q × (Σ ∪ {ε}) × (Γ ∪ {ε}) → subsets of Q × (Γ ∪ {ε})
11. 11. A convention • Sometimes we denote “transitions” by: q0 a, b / c1c2c3 q1 • This will mean: q0 a, b / c1 ε, ε / c2 ε, ε / c3 intermediate states – Intuitively, pop b, then push c1, c2, and c3 q1
12. 12. Examples • Describe PDAs for the following languages: – – – – L = {w#wR: w ∈ {0, 1}*}, Σ = {0, 1, #} L = {wwR: w ∈ Σ*}, Σ = {0, 1} L = {w: w has same number of 0s and 1s}, Σ = {0, 1} L = {0i1j: i ≤ j ≤ 2i}, Σ = {0, 1}
13. 13. Main theorem A language L is context-free if and only if it is accepted by some pushdown automaton. context-free grammar pushdown automaton
14. 14. From CFGs to PDAs • Idea: Use PDA to simulate (rightmost) derivations CFG: A → 0A1 A→B B→# A ⇒ 0A1 ⇒ 00A11 ⇒ 00B11 ⇒ 00#11 stack: input: Z0A 00#11 replace production in reverse e, A / 1A0 Z01A0 00#11 pop terminals and match Z01A 0#11 replace production in reverse e, A / 1A0 Z011A0 0#11 pop terminals and match Z011A #11 Z011B #11 PDA control: write start variable e, e / A 0, 0 / e 0, 0 / e replace production in reverse e, A / B
15. 15. 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
16. 16. Description of PDA for CFGs • Repeat the following steps: – If the top of the stack is a variable A: Choose a rule A → α and substitute A with α – 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 Z0, go to accept state
17. 17. Description of PDA for CFGs a, a / ε ε, A / αk...α1 for every production A → α1...αk for every terminal a q0 ε, ε / S q1 ε, Z0 / ε q2
18. 18. From PDAs to CFGs ✓ context-free grammar pushdown automaton • First, we simplify the PDA: – It has a single accept state qf – Z0 is always popped exactly before accepting – Each transition is either a push, or a pop, but not both
19. 19. From PDAs to CFGs • We look at the stack in an accepting computation: input state ε 0 1 ε 1 q0 q1 q3 q1 0 ε 1 ε 0 0 q7 q0 q1 q2 q1 q3 q7 a b a stack a a a a c a c c a a a a Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0 portions that preserve the stack A03 = {x: x leads from q0 to q3 and preserves stack} qf
20. 20. From PDAs to CFGs input state ε 0 1 ε 1 q0 q1 q3 q1 0 ε 1 ε 0 0 q7 q0 q1 q2 q1 q3 q7 a b a stack a a a a c c a a c a a a Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0 A11 → 0A03ε 0 A11 A03 ε qf
21. 21. From PDAs to CFGs input state ε 0 1 ε 1 q0 q1 q3 q1 0 ε 1 ε 0 0 q7 q0 q1 q2 q1 q3 q7 a b a stack a a a a c a c c a a a a Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0 Z0 A10 A03 A13 A13 → A10A03 qf
22. 22. From PDAs to CFGs qi a, qj’ qi variables: Aij qi’ ε/t start variable: A0f qj ε ,t/ b Aij → aAi’j’b qj qk Aii → ε qi qi a, Z0 /ε Aik → AijAjk qf A0f → A0ia
23. 23. Example 0, ε / a 1, a / ε q0 q1 #, ε / ε 0, ε / a ε, Z0 / ε q2 q0 1, a / ε #, ε / \$ q3 ε, \$ / ε q1 ε, Z0 / ε start variable: A02 productions: A00 → A00A00 A00 → A01A10 A00 → A03A30 A01 → A01A11 A01 → A02A21 ... A00 → ε A11 → ε A22 → ε A33 → ε A01 → 0A011 A01 → #A33 A02 → A01 q2