Pika parsing: reformulating packrat parsing as a dynamic programming algorithm solves the left recursion and error recovery problems
Luke A. D. Hutchison

TL;DR
This paper introduces Pika parsing, a novel dynamic programming approach reformulating packrat parsing to handle left recursion and error recovery efficiently, maintaining linear performance and simplifying grammar writing.
Contribution
The paper presents Pika parsing, a new reverse-order parsing algorithm that solves left recursion and error recovery issues in packrat parsing, with competitive performance on simple to moderate grammars.
Findings
Pika parser handles left recursion effectively.
It achieves better performance on simple expression grammars.
It incurs a performance penalty on complex grammars like Java.
Abstract
A recursive descent parser is built from a set of mutually-recursive functions, where each function directly implements one of the nonterminals of a grammar. A packrat parser uses memoization to reduce the time complexity for recursive descent parsing from exponential to linear in the length of the input. Recursive descent parsers are extremely simple to write, but suffer from two significant problems: (i) left-recursive grammars cause the parser to get stuck in infinite recursion, and (ii) it can be difficult or impossible to optimally recover the parse state and continue parsing after a syntax error. Both problems are solved by the pika parser, a novel reformulation of packrat parsing as a dynamic programming algorithm, which requires parsing the input in reverse: bottom-up and right to left, rather than top-down and left to right. This reversed parsing order enables pika parsers to…
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.
Code & Models
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsAlgorithms and Data Compression · Logic, programming, and type systems · Parallel Computing and Optimization Techniques
