当前位置: X-MOL 学术New Gener. Comput. › 论文详情
Our official English website, www.x-mol.net, welcomes your feedback! (Note: you will need to create a separate account there.)
Unifying Parsing and Reflective Printing for Fully Disambiguated Grammars
New Generation Computing ( IF 2.6 ) Pub Date : 2020-04-29 , DOI: 10.1007/s00354-019-00082-y
Zirun Zhu , Hsiang-Shang Ko , Yongzhe Zhang , Pedro Martins , João Saraiva , Zhenjiang Hu

Language designers usually need to implement parsers and printers. Despite being two closely related programs, in practice they are often designed separately, and then need to be revised and kept consistent as the language evolves. It will be more convenient if the parser and printer can be unified and developed in a single program, with their consistency guaranteed automatically. Furthermore, in certain scenarios (like showing compiler optimisation results to the programmer), it is desirable to have a more powerful reflective printer that, when an abstract syntax tree corresponding to a piece of program text is modified, can propagate the modification to the program text while preserving layouts, comments, and syntactic sugar. To address these needs, we propose a domain-specific language BiYacc , whose programs denote both a parser and a reflective printer for a fully disambiguated context-free grammar. BiYacc is based on the theory of bidirectional transformations, which helps to guarantee by construction that the generated pairs of parsers and reflective printers are consistent. Handling grammatical ambiguity is particularly challenging: we propose an approach based on generalised parsing and disambiguation filters, which produce all the parse results and (try to) select the only correct one in the parsing direction; the filters are carefully bidirectionalised so that they also work in the printing direction and do not break the consistency between the parsers and reflective printers. We show that BiYacc is capable of facilitating many tasks such as Pombrio and Krishnamurthi’s ‘resugaring’, simple refactoring, and language evolution.

中文翻译:

为完全消歧的语法统一解析和反射打印

语言设计者通常需要实现解析器和打印机。尽管是两个密切相关的程序,但在实践中它们通常是分开设计的,然后需要随着语言的发展进行修改并保持一致。如果解析器和打印机可以在一个程序中统一开发,自动保证一致性,会更方便。此外,在某些场景下(比如向程序员展示编译器优化结果),希望有一个更强大的反射打印​​机,当一段程序文本对应的抽象语法树被修改时,可以将修改传播到程序文本,同时保留布局、注释和语法糖。为了满足这些需求,我们提出了一种特定领域的语言 BiYacc ,其程序同时表示解析器和反射打印机,用于完全消除歧义的上下文无关语法。BiYacc 基于双向转换理论,有助于通过构造保证生成的解析器和反射打印机对是一致的。处理语法歧义特别具有挑战性:我们提出了一种基于广义解析和消歧过滤器的方法,它产生所有解析结果并(尝试)选择解析方向上唯一正确的结果;过滤器经过仔细的双向处理,因此它们也可以在打印方向上工作,并且不会破坏解析器和反射式打印机之间的一致性。我们表明 BiYacc 能够促进许多任务,例如 Pombrio 和 Krishnamurthi 的“重新加糖”、简单重构和语言进化。
更新日期:2020-04-29
down
wechat
bug