Pushdown Automata (PDA)

the stack as memory

Think of a spring-loaded stack of cafeteria plates: you can only ever put a plate ON TOP, or take the TOP plate off — you cannot reach into the middle or the bottom. That is a stack, and it is the single extra piece of memory a pushdown automaton gets beyond its finite control. Calling it 'memory' is exactly right: it lets the machine remember things, but in a strictly disciplined, last-in-first-out way.

Two properties make this memory special. First, it is UNBOUNDED: the stack can grow as tall as needed, so the machine can remember an arbitrarily large amount — for example, one marker for each of n input symbols, with no fixed limit on n. Second, its access is RESTRICTED: at any moment the machine can only see and modify the top symbol; everything underneath is invisible and untouchable until the things above it are popped away. So a PDA can store a great deal, but it can only consult it in reverse order of how it was stored.

This combination is exactly the sweet spot for nested, recursive structure. Matched parentheses, balanced begin/end blocks, and the chain of pending subroutine calls all have the property that the thing opened most recently must be closed first — which is precisely last-in-first-out. It is also exactly why a stack is too weak for some tasks: the restriction to the top means a PDA cannot freely compare information stored far apart, which is the deep reason it cannot recognise languages like a^n b^n c^n that need to count three quantities at once.

Pushing A, then B, then C gives a stack reading C-B-A from top to bottom. To reach A you must first pop C, then B. You can never peek at A while C and B sit on top of it.

Last-in, first-out: unbounded depth, but only the top is ever accessible.

Unbounded does not mean infinite-at-once: at any instant the stack holds a finite string of symbols; only its maximum height is unlimited. And only the top is readable — a stack is far weaker than a Turing tape you can scan anywhere.

Also called
stack memoryLIFO memory堆疊記憶體後進先出記憶體