[Paper Review] Yacc is dead
This paper introduces two novel parsing techniques based on generalizing Brzozowski's derivative concept: one for context-free grammars and another for parser combinators. The approach enables a compact, efficient parsing library (under 250 lines) that handles arbitrary context-free grammars and produces lazy parse forests, achieving performance of millions of tokens per second on S-Expressions in both Scala and Haskell implementations.
We present two novel approaches to parsing context-free languages. The first approach is based on an extension of Brzozowski's derivative from regular expressions to context-free grammars. The second approach is based on a generalization of the derivative to parser combinators. The payoff of these techniques is a small (less than 250 lines of code), easy-to-implement parsing library capable of parsing arbitrary context-free grammars into lazy parse forests. Implementations for both Scala and Haskell are provided. Preliminary experiments with S-Expressions parsed millions of tokens per second, which suggests this technique is efficient enough for use in practice.
Motivation & Objective
- To address the limitations of traditional parsing tools like Yacc by introducing a new, principled approach to parsing context-free languages.
- To develop a lightweight, composable parsing library that supports arbitrary context-free grammars without requiring manual grammar transformations.
- To achieve high performance and practical efficiency suitable for real-world applications, demonstrated through benchmarking on S-Expressions.
- To generalize the derivative technique—previously used for regular expressions—into the domain of context-free grammars and parser combinators.
Proposed method
- Extending Brzozowski's derivative from regular expressions to context-free grammars, enabling incremental parsing through derivative computation.
- Defining a generalized derivative operation that operates on parser combinators, allowing for modular and composable parsing construction.
- Designing a lazy parse forest representation to efficiently represent multiple possible parses of ambiguous grammars.
- Implementing the approach in both Scala and Haskell to demonstrate language-agnostic applicability and practicality.
- Using a functional, immutable style to ensure correctness and composability in the parsing library.
Experimental results
Research questions
- RQ1Can the derivative technique from regular expressions be generalized to handle arbitrary context-free grammars?
- RQ2Can parser combinators be enhanced using a generalized derivative operation to support efficient and correct parsing?
- RQ3Is it possible to build a high-performance, composable parsing library using these generalized derivatives?
- RQ4How does the performance of this derivative-based parsing approach compare to traditional tools like Yacc in practice?
Key findings
- The generalized derivative approach successfully extends to context-free grammars, enabling correct and systematic parsing of arbitrary grammars.
- The resulting parsing library is highly compact, requiring fewer than 250 lines of code in both Scala and Haskell.
- The implementation achieves high performance, parsing S-Expressions at millions of tokens per second, indicating practical efficiency.
- The use of lazy parse forests enables efficient handling of ambiguous grammars without sacrificing performance.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.