• Like
  • Save
MELJUN CORTES Automata Theory (Automata10)
Upcoming SlideShare
Loading in...5
×
 

MELJUN CORTES Automata Theory (Automata10)

on

  • 157 views

MELJUN CORTES Automata Theory (Automata10)

MELJUN CORTES Automata Theory (Automata10)

Statistics

Views

Total Views
157
Views on SlideShare
157
Embed Views
0

Actions

Likes
0
Downloads
2
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    MELJUN CORTES Automata Theory (Automata10) MELJUN CORTES Automata Theory (Automata10) Presentation Transcript

    • MELJUN P. CORTES, MBA,MPA,BSCS,ACS Fall 2008 CSC 3130: Automata theory and formal languages Pushdown automata MELJUN CORTES
    • 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
    • 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
    • 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)
    • 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) …
    • 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 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
    • Shorthand notation read 0 push a 0, ε / a #, ε / ε read # read 1 pop a 1, a / ε ε, Z0 / ε pop Z0 read, pop / push
    • 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
    • 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 × (Γ ∪ {ε})
    • 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
    • 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}
    • 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 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
    • 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 → α 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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