# Chapter 2: Context-Free Languages

## For Your Enjoyment

## Chapter 2.2, Pushdown Automata

A pushdown automaton (PDA) is a finite automaton that also
has access to a stack with infinite memory.

### Factoids

- Context-free grammars generate context-free languages (CFLs).
- Pushdown automata recognize context-free languages.
- Context-free grammars and pushdown automata are equivalent.
(Monday's reading will show how to prove this.)
- Unlike regular languages, the set of non-deterministic CFLs
is larger than the set of deterministic CFLs.

### Pushdown Automaton 6-Tuple

A pushdown automaton is a 6-tuple (Q, Σ, Γ, δ, q_{0},
F), where Q, Σ, Γ, and F are all finite sets, and

- Q is the set of states,
- Σ is the input alphabet,
- Γ is the stack alphabet,
- δ: Q × Σ
_{ε} ×
Γ_{ε} → P(Q × Γ_{ε})
is the transition function,
- q
_{0} is the start state, and
- F ⊆ Q is the set of accept states.

### Lecture Problem

- Design a PDA that recognizes {ww
^{R} | w ∈ {1,2}^{*}}.
- What is each element of the 6-tuple?
- Show the sequence of states that the PDA goes through to accept the
string 2112.
- Show the context-free grammar that generates this language.

### Active Learning Problem

- Design a PDA that recognizes
{1
^{n}2^{k}3^{n} | w ∈ {1, 2, 3}^{*}}.
- What is each element of the 6-tuple?
- Show the sequence of states that the PDA goes through to accept the
string 1122233.
- Show the context-free grammar that generates this language.

### Acceptance

PDA M accepts input w (w_{1}...w_{m} where each
w_{i} ∈ Σ_{ε}) if there is
a sequence of states r_{0}, ..., r_{m} ∈ Q and
strings s_{0}, ..., s_{m} ∈ Γ^{*}
such that

- r
_{0} = q_{0} and s_{0} = ε
- (r
_{i+1}, b) ∈ δ(r_{i}, w_{i+1}, a)
for i = 0, 1, ..., m-1 where s_{i} = at and
s_{i+1} = bt for some a, b ∈ Γ_{ε}
and t ∈ Γ^{*}
- r
_{m} ∈ F