Reference. Derivatives of Regular Expressions
Cite
Cited by (20)
Outrunning Big KATs: Efficient Decision Procedures for Variants of GKAT zhang-2026-outrunning
Kleene Algebra kappe-2025-kleene
StacKAT: Infinite State Network Verification jacobs-2025-stackat
CF-GKAT: Efficient Validation of Control-Flow Transformations zhang-2025-cf
Coqlex: Generating formally verified lexers Ouedraogo_2023
A compiler consists of a sequence of phases going from lexical analysis to code generation. Ideally, the formal verification of a compiler should include the formal verification of each component of the tool-chain. An example is the CompCert project, a formally verified C compiler, that comes with associated tools and proofs that allow to formally verify most of those components.
However, some components, in particular the lexer, remain unverified. In fact, the lexer of Compcert is generated using OCamllex, a lex-like OCaml lexer generator that produces lexers from a set of regular expressions with associated semantic actions. Even though there exist various approaches, like CakeML or Verbatim++, to write verified lexers, they all have only limited practical applicability.
In order to contribute to the end-to-end verification of compilers, we implemented a generator of verified lexers whose usage is similar to OCamllex. Our software, called Coqlex, reads a lexer specification and generates a lexer equipped with a Coq proof of its correctness. It provides a formally verified implementation of most features of standard, unverified lexer generators.
The conclusions of our work are two-fold: Firstly, verified lexers gain to follow a user experience similar to lex/flex or OCamllex, with a domain-specific syntax to write lexers comfortably. This introduces a small gap between the written artifact and the verified lexer, but our design minimizes this gap and makes it practical to review the generated lexer. The user remains able to prove further properties of their lexer. Secondly, it is possible to combine simplicity and decent performance. Our implementation approach that uses Brzozowski derivatives is noticeably simpler than the previous work in Verbatim++ that tries to generate a deterministic finite automaton (DFA) ahead of time, and it is also noticeably faster thanks to careful design choices.
We wrote several example lexers that suggest that the convenience of using Coqlex is close to that of standard verified generators, in particular, OCamllex. We used Coqlex in an industrial project to implement a verified lexer of Ada. This lexer is part of a tool to optimize safety-critical programs, some of which are very large. This experience confirmed that Coqlex is usable in practice, and in particular that its performance is good enough. Finally, we performed detailed performance comparisons between Coqlex, OCamllex, and Verbatim++. Verbatim++ is the state-of-the-art tool for verified lexers in Coq, and the performance of its lexer was carefully optimized in previous work by Egolf and al. (2022). Our results suggest that Coqlex is two orders of magnitude slower than OCamllex, but two orders of magnitude faster than Verbatim++.
Verified compilers and other language-processing tools are becoming important tools for safety-critical or security-critical applications. They provide trust and replace more costly approaches to certification, such as manually reading the generated code. Verified lexers are a missing piece in several Coq-based verified compilers today. Coqlex comes with safety guarantees, and thus shows that it is possible to build formally verified front-ends.
flap: A Deterministic Parser with Fused Lexing yallop-2023-flap
Verbatim++: verified, optimized, and semantically rich lexing with derivatives egolf-2022-verbatim
Symbolic and automatic differentiation of languages elliottSymbolicAutomaticDifferentiation2021
Verbatim: A verified lexer generator egolfVerbatim
Zippy LL(1) parsing with derivatives EdelmannZippy2020
A typed, algebraic approach to parsing krishnaswami_typed_2019
Self-certifying Railroad Diagrams: Or: How to Teach Nondeterministic Finite Automata hinze-2019-self
agdarsec — total parser combinators allais_2018
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.
Regular expression containment: Coinductive axiomatization and computational interpretation henglein_regular_2011
Total parser combinators danielssonTotalParserCombinators2010
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.
Regular-expression derivatives re-examined owensRegularexpressionDerivativesReexamined2009
Clowns to the left of me, jokers to the right (pearl): dissecting data structures mcbride-2008-clowns
Deterministic regular languages bruggemannkleinwood
Programming Techniques: Regular expression search algorithm thompsonProgrammingTechniquesRegular1968
Cites 15 works (1 here)
With notes (1)
Finite Automata and Their Decision Problems rabinFiniteAutomataTheir1959
External (14)
- Signal flow graph techniques for sequential circuit state diagrams (1963)
- A survey of regular expressions and their applications (1962)
- Design of Sequential Machines from Their Regular Expressions (1961)
- Operations on finite automata (1961)
- Delayed logic and finite state machines (1960)
- Regular expressions and state graphs for automata (1960)
- Automata and finite automata (1960)
- Realization of Events by Logical Nets (1958)
- Sequential Functions (1958)
- Finite automata and representation of events (Myhill, WADC Tech. Rep. 57-624) (1957)
- Representation of events in nerve nets and finite automata (1956)
- Gedanken-experiments on sequential machines (1956)
- A method for synthesizing sequential circuits (1955)
- The synthesis of sequential switching circuits (1954)