120 likes | 280 Views
Fall 2010. The Chinese University of Hong Kong. CSCI 3130: Automata theory and formal languages. Pushdown automata. Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130. Motivation. regular expression. NFA. DFA. syntactic. computational. is more powerful than. CFG.
E N D
Fall 2010 The Chinese University of Hong Kong CSCI 3130: Automata theory and formal languages Pushdown automata Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130
Motivation regularexpression NFA DFA syntactic computational is more powerful than CFG pushdown automaton syntactic computational
Pushdown automata versus NFA state control input 0 1 0 0 NFA
Pushdown automata state control input 0 1 0 0 … stack pushdown automaton (PDA) A PDA is like an NFA with but with an infinite stack
Pushdown automata state control input 0 1 0 0 … $ 0 1 1 stack pushdown automaton (PDA) As the PDA is reading the input, it can push / pop symbols from the top of the stack
Building a PDA state control L = {0n1n: n ≥ 1} push $ We remember each 0 by pushingx onto the stack read 0 push x read 1 When we see a 1, we pop an x from the stack pop x read 1 pop x We want to accept when we hit the stack bottom pop $ $=special marker for bottom
A PDA in action state control L = {0n1n: n ≥ 1} push $ input read 0 0 0 0 1 1 1 push x read 1 pop x … $ x x x read 1 stack pop x pop $
Notation for PDAs q0 e, e / $ push $ q1 0, e / x read 0 push x 1, x / e read 1 pop x q2 1, x / e read 1 pop x e, $ / e pop $ q3 read, pop / push
Definition of a PDA A pushdown automaton is (Q, ,, , q0, F) where: • Q is a finite set of states; • is the input alphabet; • is the stack alphabet • q0in Q is the initial state; • F Q is a set of final states; • is the transition function d: Q ( {}) ( {}) → subsets of Q (G {}) pop symbol state input symbol state push symbol
Example q0 S = {0, 1} e, e / $ G = {$, x} q1 0, e / x d(q0, e, e) = {(q1, $)} 1, x / e d(q0, e, $) = ∅ d(q0, e, x) = ∅ q2 1, x / e d(q0, 0, e) = ∅ ... e, $ / e q3 d: Q ( {}) ( {}) → subsets of Q (G {}) pop symbol state input symbol state push symbol
The language of a PDA • A PDA is nondeterministicMultiple transitions on same pop/input allowed • Transitions may but do not have to push or pop The language of a PDA is the set of all strings in S* that can lead the PDA to an accepting state