paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Grammar Repair with Examples and Tree Automata

基于示例与树自动机的文法修复
OOPSLA 10(OOPSLA1)2026匹配度 2/10 · 论文研究 CFG 歧义修复与解析器生成,属于形式语言和语法工程,并未涉及用户核心关注的静态分析、LLM/Agent 交叉、浮点程序分析或贝叶斯程序分析。虽然使用树自动机并兼具理论证明与工具实现,但与用户研究方向仅有微弱的 PL/形式化方法背景关联。引用 0 inbox
Yunjeong Lee, Gokul Rajiv, Ilya Sergey
crossref: 2026-09-10

AI 速览

一句话:提出基于示例和树自动机的 CFG 歧义修复方法,可自动生成符合设计者意图且适合解析器生成的文法。

上下文无关文法(CFG)是描述编程语言具体语法的常用形式,但其中用于确定作用域、运算符优先级与结合性的歧义难以消除。现有解析器生成工具多采用临时启发式,可能与语言设计者意图不符。本文借鉴编程示例合成(programming by example)思想,将初始 CFG 与优先级、结合性示例统一表示为树自动机(TA)。作者提出新的 TA 学习算法,将文法与示例合并为单个自动机,并提出基于可达性分析与优化的高效 TA 求交算法,显著压缩自动机规模,从而得到解析器生成器易用的惯用 CFG。作者证明了算法可靠性,实现了工具 Greta,并通过一系列案例研究验证其有效性。

问题
CFG 中的歧义会影响作用域、运算符优先级和结合性;现有解析器生成工具用临时方法消解歧义,可能与设计者意图相悖。
方法
将初始 CFG 与示例统一建模为树自动机,提出新的 TA 学习算法将文法与示例合并,并用基于可达性分析和优化的 TA 求交算法生成紧凑 CFG。
评估
证明算法可靠性,实现 Greta 工具,并在系列案例研究中展示方法的有效性。
原文摘要(Abstract)

Context-free grammars (CFGs) are the de-facto formalism for declaratively describing concrete syntax for programming languages and generating parsers. One of the major challenges in defining a desired syntax is ruling out all possible ambiguities in the CFG productions that determine scoping rules as well as operator precedence and associativity. Practical tools for parser generation typically apply ad-hoc approaches for resolving such ambiguities, which might result in a parser’s behaviour that contradicts the intents of the language designer. In this work, we present a user-friendly approach to soundly repair grammars with ambiguities, which is inspired by the programming by example line of research in automated program synthesis. At the heart of our approach is the interpretation of both the initial CFG and additional examples that define the desired restrictions in precedence and associativity, as tree automata (TAs). The technical novelties of our approach are (1) a new TA learning algorithm that constructs an automaton based on the original grammar and examples that encode the user’s preferred ways of resolving ambiguities all in a single TA, and (2) an efficient algorithm for TA intersection that utilises reachability analysis and optimizations that significantly reduce the size of the resulting automaton, which results in idiomatic CFGs amenable to parser generators. We have proven the soundness of the algorithms, and implemented our approach in a tool called Greta, demonstrating its effectiveness on a series of case studies.

链接与引用

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

BibTeX
@article{paperbot3798,
  title = {Grammar Repair with Examples and Tree Automata},
  author = {Yunjeong Lee and Gokul Rajiv and Ilya Sergey},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {10},
  number = {OOPSLA1},
  year = {2026},
  doi = {10.1145/3798242}
}