The Squirrel Parser: A Linear-Time PEG Packrat Parser Capable of Left Recursion and Optimal Error Recovery
Luke A. D. Hutchison

TL;DR
The paper introduces the squirrel parser, a linear-time PEG packrat parser capable of handling left recursion and providing optimal error recovery, improving robustness and correctness over traditional methods.
Contribution
It presents a minimal, first-principles algorithm for left recursion handling and a set of axioms for optimal error recovery, ensuring linear time complexity and robustness.
Findings
Handles all forms of left recursion without grammar rewriting
Achieves optimal error recovery with proven correctness
Maintains linear time complexity even with multiple errors
Abstract
We present the squirrel parser, a PEG packrat parser that directly handles all forms of left recursion with optimal error recovery, while maintaining linear time complexity in the length of the input even in the presence of an arbitrary number of errors. Traditional approaches to handling left recursion in a recursive descent parser require grammar rewriting or complex algorithmic extensions. We derive a minimal algorithm from first principles: cycle detection via per-position state tracking and -per-LR-cycle communication from descendant to ancestor recursion frames, and fixed-point search via iterative expansion. For error recovery, we derived a set of four axioms and twelve constraints that must be imposed upon an optimal error recovery design to ensure completeness, correctness, optimality of performance, and intuitiveness of behavior. We utilized a constraint satisfaction…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsLogic, programming, and type systems · Natural Language Processing Techniques · Formal Methods in Verification
