← Parsing · guided lesson

String Parsing & Expression Evaluation

1 / 19 · story

the story

Finite-state machine (a scanner with states)

Every tool here exists because something was too slow or broke without it. Here is what.

1951–1959 · Stephen C. Kleene; Michael O. Rabin & Dana Scott

In a 1951 RAND memo, logician Stephen Kleene studied which patterns of input a machine with a fixed, finite memory can recognise. His "regular events" are the idea behind today's regular expressions; the memo was printed in Automata Studies in 1956. In 1959 Michael Rabin and Dana Scott published "Finite Automata and Their Decision Problems": a finite set of states, and a rule that picks the next state from the current state and the next symbol. The paper also introduced machines that may guess — nondeterministic automata. It won them the 1976 Turing Award. In 1968 Ken Thompson published a way to compile a regular expression into machine code for fast text search.

the problem it solved

Deciding, one character at a time and with a fixed amount of memory, whether input matches a pattern — and splitting it into pieces along the way.

why it matters: without it

Parsers would become deep if-else ladders that accept bad input like "+-12" or "1 2" — or re-read text again and again.

sources: Kleene — Representation of Events in Nerve Nets and Finite Automata (RAND RM-704, 1951) ↗ · Rabin & Scott — Finite Automata and Their Decision Problems (IBM J. Res. Dev., 1959) ↗ · Heidelberg Laureate Forum — Michael O. Rabin (1976 Turing Award citation) ↗ · Thompson — Regular expression search algorithm (CACM, 1968) ↗

also in this chapter: Greedy value table (Roman numerals and other number systems) · Two stacks for precedence (Dijkstra's shunting-yard) · Recursive descent (one method per grammar rule) · Length-prefixed framing · Greedy line filling (and Knuth–Plass, its optimal cousin)