Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

- MELJUN CORTES Automata Theory (Auto... by MELJUN CORTES 331 views
- Chapter 2 ee202 boolean part a by CT Sabariah Salihin 1929 views
- Automata 2 by Wisam Zaq 2039 views
- Lec 03 set by Naosher Md. Zakar... 147 views
- Chapter 5 counter1 by CT Sabariah Salihin 1041 views
- Lec 01 proposition (Discrete Math... by Naosher Md. Zakar... 223 views

274 views

Published on

MELJUN CORTES Automata Theory (Automata10)

Published in:
Technology

No Downloads

Total views

274

On SlideShare

0

From Embeds

0

Number of Embeds

3

Shares

0

Downloads

44

Comments

0

Likes

1

No embeds

No notes for slide

- 1. MELJUN P. CORTES, MBA,MPA,BSCS,ACS Fall 2008 CSC 3130: Automata theory and formal languages Pushdown automata MELJUN CORTES
- 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. 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. 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. 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. 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. 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. Shorthand notation read 0 push a 0, ε / a #, ε / ε read # read 1 pop a 1, a / ε ε, Z0 / ε pop Z0 read, pop / push
- 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment