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

使用正则表达式和DFA的已验证可逆词法分析器

Verified invertible lexer using regular expressions and DFAs

Samuel Chassot, Viktor Kunčak

AI总结:

本项目在Scala中开发了一个使用Stainless验证的可逆词法分析器框架,通过正则表达式和DFA匹配器实现,并提供形式化规范与证明,确保词法分析过程的可逆性。

摘要:

在本项目中,我们探讨了可逆性在序列化与词法分析框架中的应用。回顾可知,一方面,序列化是将数据结构写入位数组的过程,而解析是相反的操作,即读取位数组并重建数据结构。另一方面,词法分析是读取字符流并根据给定规则列表将其分割为记号的过程。虽然应用于不同场景,但两者在抽象操作上相似:它们都接受简单字符列表并提取更复杂的结构。这些操作的应用领域不同,但都共享对过程可逆性的需求。例如,当对编译器美化打印的代码文件进行记号化时,人们期望得到相同的记号序列。类似地,当航天器向地面发送科学数据时,人们期望解析后的数据与航天器序列化的数据相同。本项目的想法是探索构建一个能够生成解析器/序列化器或词法分析器/美化打印器对且具有形式化验证的可逆性概念的框架。我们首先探索相关工作与框架。之后,我们介绍在Scala中开发并使用Stainless框架验证的已验证词法分析器框架。我们解释所做的实现选择,并展示规范及其证明。带有证明的词法分析器代码可在Github上获取。主分支包含正则表达式(以下称为regex)匹配器版本和已验证的可计算语言,而dfa match分支包含使用DFA匹配器的版本。

英文摘要:

In this project, we explore the concept of invertibility applied to serialisation and lexing frameworks. Recall that, on one hand, serialisation is the process of taking a data structure and writing it to a bit array while parsing is the reverse operation, i.e., reading the bit array and constructing the data structure back. While lexing, on the other hand, is the process of reading a stream of characters and splitting them into tokens, by following a list of given rules. While used in different applications, both are similar in their abstract operation: they both take a list of simple characters and extract a more complex structure. Applications in which these two operations are used are different but they share a need for the invertibility of the process. For example, when tokenising a code file that was prettyprinted by a compiler, one would expect to get the same sequence of tokens. Similarly, when a spacecraft sends scientific data to the ground, one would expect the parsed data to be the same as the one serialised by the spacecraft. The idea of this project is to explore the idea of having a framework capable of generating parser/serialiser or lexer/prettyprinter pairs with a formally verified notion of invertibility. We first explore related works and frameworks. After that, we present our verified lexer framework developed in Scala and verified using the Stainless framework1. We explain the implementation choices we make and present the specifications and their proofs. The code of the lexer with the proofs is available on Github2. The main branch contains the regular expression (called regex from now on) matcher version and the verified Computable Languages while the dfa match branch contains the version using the DFA matcher.

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

↑