← all systems · see it in The System
Parser
A parser is a software component that takes input data (typically text) and builds a data structure (a parse tree, an abstract syntax tree or another hierarchy) giving a structural representation of the input while checking for correct syntax, by the rules of a formal grammar. Walked here as the machine, with the people who write grammars and parsers as its practice; human sentence parsing as psycholinguistics studies it is booked on the shelf.
Properties published scienceour proposal
Sourced fields, and our own readings.
| born at | about 1959-1963 (compiler-compiler designed from 1959; Floyd's precedence method 1963; Meta I January 1963) |
| born precision | years |
| boundary | Inside: the lexer (scanner) where it is separate, the parse tables or parsing functions and their stack, the lookahead buffer, the error handler, the tree builder, and the grammar as held in the parser's code or tables; the people who write grammars and parsers as its practice. Outside: the input and whoever sends it (a programmer, a file, a peer on the network, an attacker), the specification the grammar is drawn from, the parser generator that builds it (a sibling tool), the consumers of its output (a compiler's middle end, an interpreter, an application, a database), and the machine it runs on. |
| nested level | Built from a lexer, a recogniser (tables and stack, or recursive functions) and a tree builder; part of a compiler's front end (compiler L3), a programming language's implementation (programming-language L3), the input-handling code of every program that reads a format or protocol (software L4, runtime and libraries); its output is the structure the next component acts on. |
| scale | technological |
Measures (18) published science
| characteristic clock: sentences parsed per second by a neural dependency parser | more than 1000 sentences per second |
| JSON parsing throughput on one core (simdjson) | gigabytes per second |
| instructions relative to RapidJSON | a quarter or fewer ratio |
| LR parsing time | linear in the input length time complexity |
| general context-free parsing, worst case | O(n^3) for CYK, Earley and GLR; best combinatorial O(n^3/log^3 n); Valiant's O(n^ω), ω < 2.373 (1975), still unbeaten time complexity |
| accuracy lost and speed gained by distilling a dependency parser to 20% of its parameters | about 1 point (UAS and LAS); 2.30x faster on CPU, 1.19x on GPU points; speed ratio |
| inference energy for 8K test sentences (full model; distilled to 20%) | 0.32; 0.24 kJ |
| share of X.509 certificates in use that are syntactically invalid | 21.5 % |
| syntactically incorrect certificates accepted by TLS libraries | 631k to 1,156k (5.7%-10.5%) across 7 libraries certificates |
| JSON parsers compared in one differential test | 22 parsers |
| centre embeddings a human reader can parse | 3 at most in written language; practically none in speech embeddings |
| typical lookahead in programming-language parsers | 1 tokens |
| C parser states without and with lookahead | about 10,000; about 300 states |
| data formats implemented in Daedalus | 20 formats |
| cadence of attacks on X.509 certificate parsing | steady over the last 10 years reports |
| CPython's PEG parser against its LL(1) parser, speed and memory | within 10% |
| syntax-error repair rate (CPCT+, 200,000 invalid Java files) | 98.37 % of files within 0.5 s |
| error locations reported: CPCT+ against panic mode | 435,812 against 981,628 error locations |
Open contentions (4) open contention
Where sources or readings disagree. Both stay on the map.
- C-278 Should network software be lenient about what it accepts?
booked: The map follows the classic principle that lenient receiving helps systems work together, and keeps the critique that it hides defects alongside.
the other reading: the robustness principle as Postel's TCP guideline that laid the foundation for an interoperable Internet (src:wp:robustness-principle); LangSec's re-reading: a strict reading should discourage ambiguity and computational complexity (src:sassaman-2011-langsec-tr); RFC 9413: some interpretations help, others harm interoperability over time; tolerance only temporarily (src:rfc9413-thomson-schinazi-2023); Allman 2011, a middle ground: the principle was formulated in an Internet of cooperators and bears on interoperability and security (src:allman-2011-robustness) - C-3840 Who built the first parser?
booked: The map keeps the competing readings; none is ruled.
the other reading: Brooker and Morris's compiler-compiler, designed from 1959, tested from March 1962 (src:wp:compiler-compiler); Floyd's 1963 precedence algorithm, the special-purpose method Knuth generalised (src:knuth-1965-lr); Schorre's Meta I, January 1963, the first metacompiler (src:wp:compiler-compiler); Irons's 1961 syntax-directed ALGOL 60 compiler (cited, not read: src:wp:compiler-compiler reference list); parsing as a human practice (the Latin pars orationis) long before any machine (src:wp:parsing) - C-3852 How do people parse a sentence as they hear it: one reading at a time, several at once, or by prediction?
booked: The map keeps the competing readings; none is ruled.
the other reading: serial and modular: one structure is built and revised only when a problem is detected (generative view, Ferreira and Clifton 1986 via src:wp:parsing); parallel, incremental, probabilistic disambiguation, difficulty as surprisal (src:hale-2001-probabilistic-earley, src:levy-2008-expectation); a bottom-up or left-corner parser merging words into phrases in left superior temporal and inferior frontal cortex (src:nelson-2017-phrase-structure); parsing as a function of working memory (src:wp:parsing); single-stage surprisal underpredicts garden-path magnitude: recovery mechanisms beyond predictability (src:van-schijndel-linzen-2021, abstract); the centre-embedding limit as a usage-based property of language in use (written against spoken), not only of working memory (src:karlsson-2007-center-embedding, abstract) - C-3890 Can scattered, inconsistent checking of input be designed out of software?
booked: The map keeps the competing readings; none is ruled.
the other reading: avoidable weaknesses of the development process (src:momot-2016-seven-turrets, abstract only); not clearly avoidable where a front end forwards input that a back end parses (src:poll-2018-langsec-revisited)
Cross-scale patterns seen here (25) our proposal
Shapes that recur when the same kind of problem is solved at different scales, and how each shows in Parser. Each links to every other system that shows it.
- causal ceiling (structural)
Limits set by the structure, not by means: whether a grammar is LR(k) for some k is undecidable (Knuth 1965); whether a grammar is ambiguous is undecidable; equivalence of two parsers is undecidable from nondeterministic context-free languages up, so no test can prove two components read alike. The - nested ladder (structural)
The Chomsky hierarchy: regular inside context-free inside context-sensitive inside recursively enumerable, each recognised by a stronger automaton; deterministic context-free sits inside unambiguous inside context-free (a half-rung); LL(k) languages properly inside LL(k+1). The two families differ: - same role, different builds (structural)
One job, turning a stream of symbols into its structure, done by LR tables and a stack, recursive functions (recursive descent, combinators), memoised backtracking (packrat), dynamic-programming charts (Earley, CYK), neural classifiers, and in the brain by networks the field reads as a left-corner p - symmetry breaking (name the cut) (structural)
An ambiguous grammar gives 1 + 2 * 3 two equally valid trees; a precedence rule (the named cut) picks one, and that choice sets the tree built after it. Knuth also shows left-to-right determinism is an asymmetric property: some languages read deterministically right to left but not left to right. - templating (structural)
One LR driver loop runs every grammar: only the tables change ('all the black details are exactly the same as in other non-LR shift-reduce parsers'); lex and yacc reimplemented as flex and Bison are reused across languages and formats. - The carry (structural)
All three faces: the wait (a shift-reduce parser holds phrases on the stack until a handle is complete and the lookahead says reduce; in cortex activity builds word by word until a merge); the lookahead (LR(k) peeks k symbols ahead so it never backs up, and packrat memoises to avoid re-waiting); ove - the whole sets the local reference (structural)
The format's specification is the whole every parser reads against, yet each parser's reading is locally consistent and the readings need not close: parser differentials, JSON's duplicate names whose handling is 'unpredictable', 22 parsers with discrepancies. - trade one property for another (structural)
Generality is paid in speed (LR linear on restricted grammars, Earley/CYK cubic on all); packrat buys linear time with space; distillation trades about 1 point of accuracy for 2.3x speed; the robustness principle buys interoperability with consistency of parser behaviour. CPython's switch to PEG tra - Umwelt: each system carves its own slice of one shared medium (structural)
Each parser carves its own slice of the same byte stream: what counts as a token and a valid input is set by its grammar; two parsers given one input may read different things (parser differentials). - who opens the door (structural)
The receiver builds its doors ahead of time: the lexer and the parse tables are generated from the grammar before any input arrives, and push parsers call handlers the application registered. - barrier-gates-complexity (partial)
LangSec: full recognition at the input boundary is the seal; without it ('shotgun' checks scattered through processing) input-handling code becomes the place exploitation occurs, and secure composition of components needs it. The complexity it gates (safe composition) is argued, not measured. - borrowed-then-held (partial)
Meta I was written directly in a pseudo-machine language; Meta II was bootstrapped from Meta I in 1963 and written in its own metalanguage: the parser-builder first borrowed, then held itself. - conservation law plus closure (partial)
A context-free grammar leaves a slot open (declare before use, types): the relaxed parser accepts a superset and a second set of rules (semantic analysis, attribute grammars) closes it. - holding / entrainment (partial)
Pull parsing: the parser asks the lexer for the next token, so the whole sets when its part ticks. - outside-to-inside (partial)
The grammar is first written outside the parser (a specification, BNF); the parser generator turns it into tables inside the parser. Outside first shown. - partner-becomes-part (partial)
Lexer and parser, separate components passing tokens, fuse in scannerless and packrat parsing, which 'allows lexical analysis to be integrated seamlessly into parsing'. - red-queen (partial)
Defenders keep building better parsers (grammar-derived, verified, Daedalus) while attacks exploiting parsers continue at a steady rate; neither side gains ground. On the defender side Dullien (2017, abstract) shows some software can be designed so a one-shot memory corruption gives no advantage, a - runaway from an unstable balance (partial)
RFC 9413: between strict and permissive there are two stable points; tolerance feeds itself (each tolerated flaw forces others to tolerate), so an ecosystem off the strict point runs to the permissive one. A second form inside one run: poor panic-mode recovery breeds spurious errors that drown out t - same shape, opposite sign (partial)
One production rule run two ways: a derivation rewrites the start symbol into a sentence (generation), an LR parse applies the same rules in reverse ('rightmost derivation in reverse'); parsing and templating, scanf and printf, are paired the same way. - seed (partial)
A finite grammar unpacks an unbounded language, and a parser generator turns one grammar into a working parser; lex and yacc were used 'for everything from programming languages to text file conversion'. - The Payment to Entropy (partial)
Thermal form: parsing costs measured energy (0.32 kJ for 8K sentences, full model) and its carbon footprint is a stated concern. Signal form: each tolerant hand-off between implementations lets errors accumulate (protocol decay). No per-hand-off efficiency given. - cephalization (surface)
LangSec asks that all checking gather at the point where input first enters (the recogniser) rather than being scattered through the code that uses it. - lightning (surface)
In human cortex activity builds with each word and drops suddenly when words merge into a phrase; a garden-path reader commits to one reading and is forced into re-analysis at the disambiguating word. Both on the shelf sibling (human parsing). - not-diluting wins (surface)
Deterministic parsers keep a constant cost per token (linear time) while general methods grow up to cubic; programming languages are written in deterministic grammars 'because fast and efficient parsers can be written for them'. - same toolkit, independent builds (surface)
Brain and machine: cortical activity during reading fits a bottom-up or left-corner parser better than transition-probability models, a design computer scientists reached separately.
Valence: what it trades, and with whom (14) published science
Each exchange with a neighbour, read from both sides: who gains, who pays, and what carries it.
- Human (Homo sapiens) via sys:written-record · Parser gain
- Internet protocol suite (TCP/IP): the layered datagram protocols every host and router runs, the RFC record that specifies them, and the community that keeps them via sys:internet · Parser mixed
- Syntax: how a language combines words into phrases and sentences (constituency and dependency, word order, agreement, recursion), how speakers build and parse it, how children learn it, how it differs across languages, and the field that studies it via sys:written-record · Parser gain
- Recursion: defining or computing a thing in terms of smaller versions of itself, as computer science and mathematics describe it, with its base cases, call stack, recursive data, induction, and its sightings in language and nature via sys:written-record · Parser gain
- Programming language via sys:written-record · Parser gain
- Compiler via sys:written-record · Parser gain
- Threat actor via sys:internet · Parser loss
- Computer hardware via sys:electromagnetic-field · Parser gain
- Software vulnerability via sys:software · Parser loss
- Data structure via sys:written-record · Parser gain
- Finite-state machine: an abstract machine in exactly one of finitely many states at a time, moved from state to state by its inputs; the lowest member of the automata hierarchy and a working design tool via sys:written-record · Parser gain
- Lexical analyzer (lexer, scanner) via sys:written-record · Parser gain
- Parser generator (Yacc) via sys:written-record · Parser gain
- Pushdown automaton via sys:written-record · Parser gain
Partners and parts published science
Built from / builds (7)
- Formal grammar
- Lexical analyzer (lexer, scanner)
- Compiler
- Symbol table
- Pushdown automaton
- Parse tree / abstract syntax tree
- Grammar writers and parser developers
Sits inside / holds (4)
expressed by (22)
- Generation/Synthesis
- Recombination/Composition
- Scaffolding/Enablement (Meta-Tooling)
- Templating / Standardization
- Quality Improvement/Refinement
- Interoperability/Transduction (Bridging)
- Encapsulation & Modularity (Abstraction)
- Internal Coordination/Regulation
- Sensing/Scanning
- Mapping/Modeling
- Uncertainty Reduction/Learning
- Active Experimentation / Probing (Optimal Experimental Design)
- Trail-Marking / Externalized Memory (Stigmergy)
- Hypothesis Portfolio / Multiple Hypothesis Tracking
- Reactive Response
- Proactive Defense
- Physical/Virtual Barrier
- Technique-Based Identification (a.k.a. Technique-Based Detection)
- Validation of Effectiveness
- Resilience & Repair
- Redundancy & Diversity
- Quality Control & Error Correction
floor filled by (17)
- Human (Homo sapiens)
- Written record (durable external marks: texts, archives, canon)
- Computer memory
- Software
- Internet
- Compiler
- Computer hardware
- Interpreter
- Formal grammar
- Data structure
- Finite-state machine: an abstract machine in exactly one of finitely many states at a time, moved from state to state by its inputs; the lowest member of the automata hierarchy and a working design tool
- Lexical analyzer (lexer, scanner)
- Symbol table
- Parser generator (Yacc)
- Pushdown automaton
- Parse tree / abstract syntax tree
- Statistical and neural natural-language parser
Kinds (13)
- LR parser
- Recursive descent parser
- LL parser (top-down, recursive descent)
- Earley parser (chart parser)
- CYK parser
- GLR parser
- Packrat / PEG parser
- Parser combinator
- Statistical and neural natural-language parser
- Push parser (event-driven)
- Incremental parser
- Human sentence parsing (psycholinguistics)
- Semantic parser
wired (2)
Notes published science
- Donald Knuth's 1965 paper that founded LR parsing already said its theory might help explain 'the fact that certain English sentences are unintelligible to a listener'; in 2001 a probabilistic version of Earley's 1968 parser was shown to predict where human readers stumble on garden-path sentences (src:knuth-1965-lr, src:hale-2001-probabilistic-earley).
- Recorded from electrodes inside people's brains during reading, activity in the language areas climbs with each word and then drops suddenly the moment the words can be merged into a phrase, the signature the authors read as a bottom-up or left-corner parser running in cortex (src:nelson-2017-phrase-structure).
- When 11 million web certificates were checked with a parser built straight from the X.509 grammar, 21.5% turned out to be syntactically invalid, and seven widely used TLS libraries accepted between 5.7% and 10.5% of the broken ones as valid, 'including instances with security critical mis-parsings' (src:barenghi-2018-x509).
- Beating a fifty-year-old parsing algorithm would also crack a famous graph problem: Valiant's 1975 bound for parsing any context-free grammar still stands, and Abboud, Backurs and Vassilevska Williams showed that improving it even for small fixed grammars would give a breakthrough for finding cliques in graphs, and the same argument reaches RNA folding (src:abboud-2015-valiant).
Layers
The ways it takes in its world, where they meet, and how it acts back, each from L1 (where it meets the world) up.
a parser as computer scientists describe it: a stream of symbols in, through tokens and the grammar's recognition, to a structure handed on and acted on (reader's view)
- L1: The input stream: characters or bytes in a file, a document or a network message (source code, JSON, XML, HTML, certificates), or the words of a sentence
- L2: Lexical analysis: a scanner, usually a finite-state machine from regular expressions, splits the characters into tokens (scannerless parsers fold this floor into the next)
- L3: Recognition: the automaton and stack apply the grammar's rules, top-down (LL, recursive descent: predict and match) or bottom-up (LR: shift and reduce), with k tokens of lookahead
- L4: Structure: a parse tree, abstract syntax tree or other hierarchy; for ambiguous input, a parse forest
- L5: Validation and the verdict: contextual rules the grammar cannot carry, checked after a relaxed parse; syntax errors reported, repaired or recovered from; the input accepted or rejected
- L6: Output contract: the tree type, AST schema or event interface that the consuming component is built against (CPython's internal AST converted to ast.AST objects; a verified parser's value-and-length result; registered callbacks)
- L7: Action on the input: the program works out what the validated input means and acts (an interpreter evaluates, a compiler generates code, a browser renders) or refuses it
the boardroom (shared floors)
- L3: Recognition: the automaton and its stack (or recursive functions) apply the grammar to the tokens, top-down or bottom-up, choosing with k tokens of lookahead; deterministic methods in linear time, general ones up to cubic
- L4: Structure: phrases reduced into one tree (parse tree, abstract syntax tree), or a parse forest for ambiguous input
- L5: Validation and the verdict: contextual rules the grammar cannot carry, limits, syntax errors reported, repaired or recovered from; the input accepted or rejected
- L6: Output contract: the tree type, AST schema or event interface that the consuming component is built against (CPython's internal AST converted to ast.AST objects; a verified parser's value-and-length result; registered callbacks)
- L7: Action on the input: the program works out what the validated input means and acts (evaluate, generate code, render, answer) or refuses it
way in: A person's edits to a file open in an editor (incremental parsing)
- L1: The edited text of a file
way in: Hand-parsed corpora (treebanks) for statistical and neural parsers
- L1: Sentences annotated with their structure by hand (a treebank such as the Penn Treebank)
- L2: Learned statistics or dense features: how often constructions occur in context
way in: Messages and documents arriving over the network (JSON, X.509 certificates, TLS, HTML)
- L1: Bytes of a protocol message or data-format document received from a peer
- L2: Framing and structural indexing: the encoding checked and the structural characters located (simdjson's first stage, with SIMD instructions)
way in: Names already declared (the symbol table fed back to the lexer)
- L1: The symbol table's entries in memory: typedef names and variable names
- L2: The lexer asks the symbol table before it gives a name its token class
way in: Resource limits: memory, text size, nesting depth
- L1: The machine's memory and the limits an implementation sets
- L2: Caps set inside the parser: memory allocated to one parser capped, or entities expanded lazily only when used
- L3: Recursion handled in constant stack space by design
way in: Test inputs run through several parsers of one format (differential testing, red teams)
- L1: Generated or collected inputs, each given to many parsers
- L2: Consensus normalisation: each parser's output reduced to a common form for comparison
way in: Text in a computer or data language (source code, documents, files)
- L1: Characters in a file or document, written by people or generated by programs
- L2: The lexer: a finite-state machine from regular expressions groups characters into tokens
way in: The grammar (and the specification it is drawn from)
- L1: Grammar rules (BNF, EBNF, PEG, ASN.1-derived) written by language and format designers
- L2: The parser generator reads the grammar and derives the tables (the LR automaton, itself a finite-state machine over stack symbols), or the grammar is hand-translated into recursive functions
way in: The parser's own stack (its left context)
- L1: The parse stack in memory: previously parsed phrases and their states
- L2: The topmost state number summarises all relevant left context
way out: Energy spent as heat by the machine that parses
- L1: Energy consumed in inference (0.32 kJ for 8K sentences with the full model)
- L3: Parsing computation on a CPU or GPU
way out: Events to registered handlers (push parsing)
- L1: The application's handler code runs
- L3: Relevant tokens detected during recognition
way out: Refusal to a peer: a fatal error instead of recovery
- L1: The peer meets the refusal (a terminated connection)
- L5: A fatal error is generated for a condition the specification does not allow
way out: Serialisation (unparsing): a value written back as bytes, paired with the parser
- L1: Formatted output: the complement of parsing (printf to scanf)
- L6: A parser and its serialiser verified as one pair over a non-malleable format
way out: Syntax error messages to the person
- L1: A message listing what could have come next
- L5: The error is found at a blank table cell
way out: The program's action: evaluate, generate code, render
- L1: An interpreter evaluates, a compiler generates code
- L7: The implications of the validated input are worked out
way out: The tree or internal representation handed to the consumer (compiler middle end, interpreter, application)
- L1: Held in memory for the next component
- L6: The internal representation is handed on