4.6.11 · D1Theory of Computation

Foundations — Equivalence of CFGs and PDAs

2,251 words10 min readBack to topic

This page is the ground floor. The parent topic throws a lot of notation at you: , , , , , , , , , . We define each one from zero, anchor it to a picture, and say why the topic needs it — in an order where every item leans only on the ones before it.


1. Symbols, strings, and the empty string

Why the topic needs . In Direction 1 the PDA applies a grammar rule without reading any input — that "read nothing" is written . In Direction 2 the rule means "go nowhere, read nothing." If you don't have a name for "the string of length zero," you cannot write either.


2. Sets and the star

Picture as an ever-growing list: first , then all length-1 strings, then all length-2 strings, forever.

Why the topic needs . A grammar rule says is some string of variables-and-terminals; that "some string, any length" is precisely what captures.


3. The last-in-first-out picture: a stack

Everything in this topic rides on one data structure. Meet it before any automaton.

Why the topic needs it. In Direction 1 the stack literally stores "the part of the string I still owe you." In Direction 2, a balanced push-then-pop on the stack is the bracket structure that a grammar variable expands into.


4. A grammar:

Now we can read the parent's grammar tuple, piece by piece.


5. Derivation arrows: and

Picture a chain of pictures: . Each arrow is one box being replaced.

Why the topic needs . The variable in Direction 2 is defined by — " can be rewritten, in some number of steps, into the pure string ." No star arrow, no way to state that meaning.


6. A machine's control: , , , and

The parent writes moves like . Decode it: in state , reading nothing (), with on top of the stack, one allowed outcome ( means "contains as a member") is: stay in and push .


7. The stack alphabet: and

Why two alphabets? The machine reads input letters () but may want to remember them using different scratch symbols (). Keeping them separate lets the stack store bookkeeping (like grammar variables) that never appears in the input.


8. Putting a PDA together:


9. The triple variable

You now have every piece to read Direction 2's key invention.

Why the topic needs it. This is the bridge that turns "a run of the machine" into "an expansion of a grammar box." Because a balanced dip is a nesting shape (§3), it is exactly what a CFG variable can generate — that is the entire trick of Direction 2.


How these foundations feed the topic

symbols and empty string eps

strings and star

stack LIFO nesting

grammar V Sigma R S

derivation arrows

PDA states delta Gamma Z0

variable A_pq balanced run

Equivalence of CFGs and PDAs

Read top to bottom: raw symbols build strings; strings and the star give both grammars and the stack picture; the stack + states make a PDA; grammars + arrows give derivations; and the balanced-run variable fuses machine-runs with grammar-boxes, delivering the equivalence in the parent topic.


Equipment checklist

Cover the right side and answer each before moving on.

What is and what is its length?
The empty string; length (not a space, not the number zero).
What does mean?
Every string over alphabet , of any length including .
State the LIFO rule of a stack in one line.
The last symbol pushed is the first one popped; you can only touch the top.
Why does a stack model recursion/nesting?
Inner (last-pushed) items must be finished/popped before outer ones — the exact order nested boxes open.
Name the four parts of a CFG .
Variables, terminals, rules, start variable.
What does the bar mean in a rule?
"Or" — alternative right-hand sides for the same variable.
What does mean?
You can get from to by applying zero or more rules.
What is a leftmost derivation?
One that always expands the left-most remaining variable first.
In , decode every part.
In state , reading nothing, with on top, one allowed move is: stay in and push .
Why is used instead of for ?
returns a set of moves — nondeterminism, several legal choices at once.
What are and ?
The stack alphabet, and the single initial bottom-of-stack symbol.
Name the two acceptance modes and their relation.
By final state and by empty stack; they recognise the same language class.
What does mean?
runs from state to state on input with balanced, net-zero stack usage.
Recall One-line summary

Grammar-nesting and stack-LIFO are the same shape; every symbol above () exists to write down that one match.