Formally Verified Linear-Time Invertible Lexing
Samuel Chassot, Viktor Kuncak
Abstract
Abstract We present ZipLex , a verified framework for invertible linear-time lexical analysis following the longest match (maximal munch) semantics. Unlike past verified lexers that focus only on satisfying the semantics of regular expressions and the longest match property, ZipLex also guarantees that lexing and printing are mutual inverses. Thanks to verified memoization, it also ensures that the lexical analysis of a string is linear in the size of the string. Our design and implementation rely on two sets of ideas: (1) a new abstraction of token sequences that captures the separability of tokens in a sequence while supporting their efficient manipulation, and (2) a combination of verified data structures and optimizations, including Huet’s zippers and memoization with a standalone verified imperative hash table. Our hash table offers competitive performance as shown by our evaluation. We implemented and verified ZipLex using the Stainless deductive verifier for Scala. Our evaluation demonstrates that ZipLex supports realistic applications such as JSON processing and lexers of programming languages, and behaves linearly even in cases that make flex-style approaches quadratic. ZipLex is two orders of magnitude faster than Verbatim, showing that verified invertibility and linear-time algorithms can be developed without prohibitive cost. Compared to Coqlex, ZipLex also offers linear (instead of quadratic) time lexing, and is the first lexer that comes with invertibility proofs for printing token sequences.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext 7a8d9991-187c-4e75-bcbb-556367d3f809Builds on4
- Zippy LL(1) parsing with derivativesRomain Edelmann, Jad Hamza, Viktor KuncakPLDI 2020 · 13 citations
- RE#: High Performance Derivative-Based Regex Matching with Intersection, Complement, and Restricted LookaroundsIan Erik Varatalu, Margus Veanes, Juhan P. ErnitsPOPL 2025 · 9 citations
- Efficient Algorithms for the Uniform Tokenization ProblemAngela W. Li, Konstantinos MamourasOOPSLA 2025 · 3 citations
- Verified and Optimized Implementation of Orthologic Proof SearchSimon Guilloud, Clément Pit-ClaudelCAV 2025
Related papers
- Formally Verifying Arithmetic Chisel Designs for All Bit Widths at OnceWeizhi Feng, Yicheng Liu, Jiaxiang Liu, David N. Jansen et al.DAC 2024
- Formula Normalizations in VerificationSimon Guilloud, Mario Bucev, Dragana Milovancevic, Viktor KuncakCAV 2023 · 6 citations
- Flux: Liquid Types for RustNico Lehmann, Adam T. Geller, Niki Vazou, Ranjit JhalaPLDI 2023 · 29 citations
- Vest: Verified, Secure, High-Performance Parsing and Serialization for RustYi Cai, Pratap Singh, Zhengyao Lin, Jay Bosamiya et al.USENIX Security 2025
- StarMalloc: Verifying a Modern, Hardened Memory AllocatorAntonin Reitz, Aymeric Fromherz, Jonathan ProtzenkoOOPSLA 2024 · 5 citations
