基于示例和树自动机的语法修复:扩展版
Grammar Repair with Examples and Tree Automata: Extended Version
AI总结:
本研究提出基于示例和树自动机的语法修复方法,通过构建自动机解决语法歧义,提升解析器生成的准确性与实用性。
摘要:
上下文无关文法(CFG)是描述编程语言具体语法的事实性形式化方法,并用于生成解析器。在定义期望语法的主要挑战之一是消除所有可能的CFG生产式中的歧义,这些生产式决定了作用域规则以及运算符优先级和结合性。实际的解析器生成工具通常应用随意的方法来解决此类歧义,这可能导致解析器的行为与语言设计者意图相矛盾。在本工作中,我们提出了一种用户友好的方法,以正确地修复具有歧义的语法,该方法受到自动化程序合成中编程示例研究的启发。我们方法的核心是将初始CFG以及额外的示例(定义期望的优先级和结合性限制)解释为树自动机(TAs)。我们方法的技术新颖性包括(1)一种新的TA学习算法,该算法基于原始语法和示例构建一个自动机,这些示例编码了用户偏好的歧义解决方式,全部在一个TA中;(2)一种高效的TA交集算法,利用可达性分析和优化,显著减少了结果自动机的大小,从而产生适合解析器生成器的idiomatic CFGs。我们已经证明了算法的正确性,并在名为Greta的工具中实现了我们的方法,在一系列案例研究中展示了其有效性。
英文摘要:
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 behavior 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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。