Reference. Total parser combinators
A monadic parser combinator library which guarantees termination of parsing, while still allowing many forms of left recursion, is described. The library’s interface is similar to those of many other parser combinator libraries, with two important differences: one is that the interface clearly specifies which parts of the constructed parsers may be infinite, and which parts have to be finite, using dependent types and a combination of induction and coinduction; and the other is that the parser type is unusually informative.
The library comes with a formal semantics, using which it is proved that the parser combinators are as expressive as possible. The implementation is supported by a machine-checked correctness proof.
Cite
Cited by (9)
Intrinsic Verification of Parsers and Formal Grammar Theory in Dependent Lambek Calculus intrinsic-verification-of-parsers
We present Dependent Lambek Calculus (Lambek), a domain-specific dependent type theory for verified parsing and formal grammar theory. In Lambek, linear types are used as a syntax for formal grammars, and parsers can be written as linear terms. The linear typing restriction provides a form of intrinsic verification that a parser yields only valid parse trees for the input string. We demonstrate the expressivity of this system by showing that the combination of inductive linear types and dependency on non-linear data can be used to encode commonly used grammar formalisms such as regular and context-free grammars as well as traces of various types of automata. Using these encodings, we define parsers for regular expressions using deterministic automata, as well as examples of verified parsers of context-free grammars.
We present a denotational semantics of our type theory that interprets the linear types as functions from strings to sets of abstract parse trees and terms as parse transformers. Based on this denotational semantics, we have made a prototype implementation of Lambek using a shallow embedding in the Agda proof assistant. All of our examples parsers have been implemented in this prototype implementation.
Verified ALL(*) Parsing with Semantic Actions and Dynamic Input Validation lasserCoStar2023
CoStar: A verified ALL(*) parser lasserCoStarVerifiedALL2021
A type- and scope-safe universe of syntaxes with binding: their semantics and proofs allais-2021-a
Algorithmics bird-2021-algorithmics
Zippy LL(1) parsing with derivatives EdelmannZippy2020
agdarsec — total parser combinators allais_2018
Certified Normalization of Context-Free Grammars firsovCertifiedNormalizationContextFree2015
Parsing with derivatives: A functional pearl mightParsingDerivativesFunctional2011
We present a functional approach to parsing unrestricted context-free grammars based on Brzozowski’s derivative of regular expressions. If we consider context-free grammars as recursive regular expressions, Brzozowski’s equational theory extends without modification to context-free grammars (and it generalizes to parser combinators). The supporting actors in this story are three concepts familiar to functional programmers - laziness, memoization and fixed points; these allow Brzozowski’s original equations to be transliterated into purely functional code in about 30 lines spread over three functions.
Yet, this almost impossibly brief implementation has a drawback: its performance is sour - in both theory and practice. The culprit? Each derivative can double the size of a grammar, and with it, the cost of the next derivative.
Fortunately, much of the new structure inflicted by the derivative is either dead on arrival, or it dies after the very next derivative. To eliminate it, we once again exploit laziness and memoization to transliterate an equational theory that prunes such debris into working code. Thanks to this compaction, parsing times become reasonable in practice.
We equip the functional programmer with two equational theories that, when combined, make for an abbreviated understanding and implementation of a system for parsing context-free languages.
Cites 48 works (2 here)
With notes (2)
Applicative programming with effects mcbride-2008-applicative
Derivatives of Regular Expressions brzozowskiDerivativesRegularExpressions1964
External (46)
- Parsing mixfix operators (2011)
- The Agda Wiki (2010)
- Termination checking in the presence of nested inductive and coinductive types (2010)
- Dependently typed grammars (2010)
- Beating the Productivity Checker Using Embedded Languages (2010)
- TRX: A Formally Verified Parser Interpreter (2010)
- Subtyping, declaratively: an exercise in mixed induction and coinduction (2010)
- Typed transformations of typed grammars: The left corner transform (2009)
- A Kleene theorem for polynomial coalgebras (2009)
- Representations of Stream Processors Using Nested Fixed Points (2009)
- Strongly specified parser combinators (2009)
- A Hoare Logic for the State Monad (2009)
- Parsec-like parser combinator that handles left recursion? (Haskell-Cafe message) (2009)
- Structurally recursive descent parsing (2008)
- Parser combinators for ambiguous left-recursive grammars (2008)
- Partial Parsing: Combining Choice with Commitment (2008)
- Towards a practical programming language based on dependent type theory (Norell, PhD thesis) (2007)
- FUNCTIONAL PEARL Parallel Parsing Processes (2004)
- Polish parsers, step by step (2003)
- Pure functional parsing (2002)
- Seeing and doing (McBride & McKinna, talk) (2002)
- Embedded Languages for Describing and Verifying Hardware (Claessen, PhD thesis) (2001)
- Parsec: Direct style monadic parser combinators for the real world (UU-CS-2001-35) (2001)
- Observable sharing for functional circuit description (1999)
- Efficient combinator parsers (1999)
- Automata and coinduction (an exercise in coalgebra) (1998)
- Fudgets - Purely Functional Processes with applications to Graphical User Interfaces (PhD thesis) (1998)
- How to add laziness to a strict language, without even being odd (1998)
- Deterministic, error-correcting combinator parsers (1996)
- Memoization in top-down parsing (1995)
- Parsing with fixed points (1995)
- Functional parsers (1995)
- Garbage collection, and memory efficiency, in lazy functional languages (Röjemo, PhD thesis) (1995)
- Infinite objects in type theory (1994)
- Higher-order functions for parsing (1992)
- Calculating Compilers (Meijer, PhD thesis) (1992)
- Unification and anti-unification in the calculus of constructions (1991)
- On Kleene algebras and closed semirings (1990)
- Inductive Definition in Type Theory (Mendler, PhD thesis) (1988)
- Making form follow function: An exercise in functional programming style (1987)
- A Categorical Programming Language (Hagino, PhD thesis) (1987)
- How to replace failure by a list of successes a method for exception handling, backtracking, and pattern matching in lazy functional languages (1985)
- On the semantics of fair parallelism (1980)
- Theoretical Issues in the Implementation of Programming Languages (Solomon, PhD thesis) (1977)
- Recursive Programming Techniques (1975)
- A note on enumerable grammars (1969)