arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2510.18479cs.PLcs.FL
收藏

形式验证的线性时间可逆词法分析

Formally Verified Linear-Time Invertible Lexing

EPFL(洛桑联邦理工学院)

Samuel Chassot, Viktor Kunčak

AI总结:

本文提出ZipLex,一种形式验证的线性时间可逆词法分析框架,支持最长匹配语义。该框架通过验证记忆化确保词法分析线性时间,同时保证词法分析与打印互为逆操作,适用于JSON处理等实际应用。

摘要:

我们提出了ZipLex,一种形式验证的可逆线性时间词法分析框架,遵循最长匹配(最大吞噬)语义。与以往仅关注正则表达式语义和最长匹配性质的验证词法分析器不同,ZipLex还保证词法分析与打印互为逆操作。得益于验证的记忆化,它还确保字符串的词法分析时间与其大小成线性关系。我们的设计和实现依赖于两个思想集:(1)一种新的标记序列抽象,能够捕捉序列中标记的分离性并支持高效操作;(2)验证数据结构与优化的结合,包括Huet的zipper和使用独立验证的命令式哈希表的记忆化。我们的哈希表在评估中表现出竞争力。我们使用Stainless deductive verifier for Scala实现了并验证了ZipLex。我们的评估显示,ZipLex支持实际应用,如JSON处理和编程语言词法分析,并在使flex风格方法二次的案例中表现线性。ZipLex比Verbatim++快两个数量级,证明了形式验证的可逆性和线性时间算法可以无成本开发。与Coqlex相比,ZipLex提供了线性(而非二次)时间词法分析,并且是第一个附带打印标记序列可逆性证明的词法分析器。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑