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.


翻译:上下文无关语法(CFG)是声明式描述编程语言具体语法并生成解析器的实际标准形式化工具。定义期望语法的主要挑战之一在于排除CFG产生式中所有可能的歧义,这些产生式决定了作用域规则以及运算符优先级和结合性。实用的解析器生成工具通常采用临时性方法解决此类歧义,可能导致解析器行为与语言设计者的意图相悖。本研究提出一种用户友好的方法,可对存在歧义的语法进行可靠修复,其灵感来源于自动化程序合成领域中的示例编程研究方向。我们方法的核心在于将初始CFG与定义优先级和结合性约束的附加示例统一解释为树自动机(TA)。本方法的技术创新在于:(1)提出新型TA学习算法,能够基于原始语法和编码用户偏好歧义解决方式的示例,在单一TA中构建自动机;(2)设计高效的TA交集算法,利用可达性分析和优化技术显著缩减结果自动机规模,从而生成适用于解析器生成器的惯用CFG。我们已证明算法的可靠性,并在名为Greta的工具中实现了该方法,通过系列案例研究验证了其有效性。

0
下载
关闭预览

相关内容

专知会员服务
65+阅读 · 2021年5月29日
【新书】自然语言处理表示学习技术,349页pdf,清华大学
专知会员服务
174+阅读 · 2020年7月11日
语音情绪识别|声源增强|基频可视化
深度学习每日摘要
15+阅读 · 2019年5月5日
强化学习与文本生成
微信AI
41+阅读 · 2019年4月4日
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
国家自然科学基金
5+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Arxiv
0+阅读 · 2月15日
VIP会员
最新内容
人工智能赋能无人机:俄乌战争(万字长文)
专知会员服务
5+阅读 · 今天6:56
国外海军作战管理系统与作战训练系统
专知会员服务
2+阅读 · 今天4:16
美军条令《海军陆战队规划流程(2026版)》
专知会员服务
10+阅读 · 今天3:36
《压缩式分布式交互仿真标准》120页
专知会员服务
4+阅读 · 今天3:21
《电子战数据交换模型研究报告》
专知会员服务
6+阅读 · 今天3:13
《基于Transformer的异常舰船导航识别与跟踪》80页
《低数据领域军事目标检测模型研究》
专知会员服务
6+阅读 · 今天2:37
【CMU博士论文】物理世界的视觉感知与深度理解
专知会员服务
10+阅读 · 4月22日
相关VIP内容
专知会员服务
65+阅读 · 2021年5月29日
【新书】自然语言处理表示学习技术,349页pdf,清华大学
专知会员服务
174+阅读 · 2020年7月11日
相关基金
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
国家自然科学基金
5+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员