Pushdown Automata

Pushdown Automata

On Pushdown Automaton v. Finite Automaton:

A finite automaton reads a single tape of input in one direction.

A pushdown automaton also reads an input tape, but it also has an additional tape that it can read and write to.

Stack: A PDA can write and read symbols to the stack.

Push In Notation (r,o \to i)

Example: r,o \to i

Formal: Let \Gamma be an alphabet, then:

Example: Marking End of Stack

Examples

Example: Simple PDA

Example: Write a PDA that accepts { a^n b^{3n} }

Example: Write a PDA that accepts { a^n b^{3n+1} }

Example: Write a PDA that accepts { a^n b^{m} | m \ge 3 }

What We Need to Know

Formal Definition

A pushdown automaton is a 6-tuple (Q, \Sigma, \Gamma, \delta, q_0, F) where:

  1. Q: Set of states
  2. \Sigma: Input alphabet
  3. \Gamma: Stack alphabet.
  4. \delta: Q \times \Sigma_\epsilon \times \Gamma_\epsilon \to P(Q \times \Gamma_\epsilon) is transition function
  5. q_0 \in Q: Start state
  6. F \subseteq Q

Q, \Sigma, \Gamma, and F are finite.

Generic Grammar to PDA

Example

Suppose the grammar

S \to a^2 S b | \epsilon

We’ll write the parse tree:

We will begin copying the parse tree onto a PDA’s stack tape now:

From layer one we have:

aaSb$

When we read a terminal, we want to pop it off the stack. e.g.,

Suppose we’ve read two as and now have to expand S.

Sb$
  1. Pop S (\epsilon, \epsilon \to S)
  2. Push b (\epsilon, b \to \epsilon)
  3. Push S (\epsilon, S \to \epsilon)
  4. Push a (\epsilon, a \to \epsilon)
  5. Push a (\epsilon, a \to \epsilon)
aaSbb$

The PDA so far looks like:

  1. Push $
  2. Push S
  3. Major Loop:
    1. Pop S
    2. Push b
    3. Push S
    4. Push a
    5. Push a
  4. Read a, pop a (x2)
  5. Major Loop OR just pop S and push epsilon.

Finally, to account for b, we just read the right number of bs and then pop $ to reach the accepting state.

Steps

  1. Push $ and start variable

  1. \forall rule: A \to w:

  1. \forall t \in \Gamma:

  1. \epsilon, \$ \to \epsilon from loop to accept.

More Examples

A

S \to aTb|b \\ T \to Ta|\epsilon

B

a^i b^j c^k | i,j,k \ge 0 \text{ and } i = h \lor i = k

Divide and conquer.