lexer-fsm-parser-pushdown-automaton

IN premiseentries/2026/06/21/wiki-Tokenization_lexical_analysis-chunk-1.md

Created 2026-06-21T09:50:10+00:00

In compiler design, the lexer uses a finite-state machine (FSM) while the parser uses a pushdown automaton (stack-based); regular expressions cannot count or match recursive structures.

Summary

The compiler splits its work into two stages because they demand different levels of memory: recognizing simple tokens only needs to track which state it is in, but parsing sentences with nested or recursive structure (like matching brackets or grammar rules) requires a stack to remember what is still open. This division isn't an arbitrary design choice; the extra machinery at the parsing stage is forced by the fact that regular pattern-matching simply cannot count or verify that structures are properly closed.

Dependents

These beliefs depend on this one: