paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Static Inference of Regular Grammars for Ad Hoc Parsers

ad hoc 解析器正则文法的静态推断
OOPSLA 9(OOPSLA2)2025匹配度 3/10 · 该论文属于纯 PL/静态分析方向(精化类型推断与抽象解释),研究 ad hoc 解析器的正则文法推断,与用户核心关心的 PL 与 AI/LLM/Agent 交叉、浮点程序分析或贝叶斯程序分析均无直接关联。引用 1 inbox
Michael Schröder, Jürgen Cito
crossref: 2026-09-10

AI 速览

一句话:提出用精化类型推断从无标注 ad hoc 解析器源码中静态推断正则输入文法,并实现 Panini 系统。

实践中大量解析器是 ad hoc 编写的:直接用字符串操作处理输入而不显式定义文法,且常与业务逻辑交织,易产生隐蔽语义错误;完整文法虽有助于理解、测试与调试,但手工编写(如正则表达式)繁琐易错。本文受类型推断启发,提出从无标注 ad hoc 解析器源码静态推断正则输入文法的通用方法:用精化类型推断合成刻画正则解析操作的逻辑与字符串约束,再通过抽象语义解释为正则表达式。作者给出核心演算、将文法推断表述为精化推断、求解字符串精化变量的抽象解释框架及多个抽象域,并实现 Panini。在 204 个 Python ad hoc 解析器上的评估显示,Panini 以 100% 精度、93% 平均召回率、约 0.82±2.85 秒耗时优于现有方法,且无需输入空间先验知识。

问题
实践中解析器多为 ad hoc 编写,不显式定义输入文法且与业务逻辑交织,导致语义错误难以发现;而手工编写完整文法又繁琐易错。
方法
借鉴类型推断思想,用精化类型推断从无标注解析器源码合成字符串与逻辑约束,再经抽象解释求解并转化为正则表达式;论文给出核心演算、精化推断形式化与多个抽象域,实现在 Panini 中。
评估
在 204 个 Python ad hoc 解析器基准上评估,Panini 达到 100% 精度与 93% 平均召回率,平均耗时 0.82±2.85 秒,优于现有方法且无需输入空间先验知识。
原文摘要(Abstract)

Parsing—the process of structuring a linear representation according to a given grammar—is a fundamental activity in software engineering. While formal language theory has provided theoretical foundations for parsing, the most common kind of parsers used in practice are written ad hoc. They use common string operations without explicitly defining an input grammar. These ad hoc parsers are often intertwined with application logic and can result in subtle semantic bugs. Grammars, which are complete formal descriptions of input languages, can enhance program comprehension, facilitate testing and debugging, and provide formal guarantees for parsing code. But writing grammars—e.g., in the form of regular expressions—can be tedious and error-prone. Inspired by the success of type inference in programming languages, we propose a general approach for static inference of regular input string grammars from unannotated ad hoc parser source code. We use refinement type inference to synthesize logical and string constraints that represent regular parsing operations, which we then interpret with an abstract semantics into regular expressions. Our contributions include a core calculus ?? Σ for representing ad hoc parsers, a formulation of (regular) grammar inference as refinement inference, an abstract interpretation framework for solving string refinement variables, and a set of abstract domains for efficiently representing the constraints encountered during regular ad hoc parsing. We implement our approach in the Panini system and evaluate its efficacy on a benchmark of 204 Python ad hoc parsers. Compared with state-of-the-art approaches, Panini produces better grammars (100 % precision, 93 % average recall) in less time (0.82 ± 2.85 s) without prior knowledge of the input space.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@article{paperbot2943,
  title = {Static Inference of Regular Grammars for Ad Hoc Parsers},
  author = {Michael Schröder and Jürgen Cito},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {9},
  number = {OOPSLA2},
  year = {2025},
  doi = {10.1145/3763054}
}