我们提出了一个用于解析表达式文法(PEGs)的计算模型。PEGs 的前身——自顶向下解析语言(TDPLs)由 A. Birman 和 J. Ullman 在 20 世纪 60 年代发现,B. Ford 在 2004 年证明了这两种形式体系识别同一类语言,即解析表达式语言(PELs)。A. Birman 和 J. Ullman 建立了诸如 TDPLs 能生成任意 DCFL 以及一些非上下文无关语言(如 $a^nb^nc^n$)等重要性质,同时也构造了一个线性时间解析算法。但由于该解析算法在 60 年代不实用,TDPLs 被放弃,随后由 B. Ford 升级为 PEGs,因此解析算法也(从实用角度)得到了改进。如今 PEGs 被积极用于编译器(例如,Python 用 PEG 解析器取代了 LL(1) 解析器)以及文本处理。在本文中,我们提出了 PEG 的计算模型,获得了 PELs 的结构性质,即证明了 PELs 包含 DCFLs 的正则闭包的布尔闭包,并且 PELs 在与 DCFLs 的正则闭包进行左拼接运算下封闭。我们基于计算模型的扩展提出了 PELs 类的扩展。我们的模型是对确定性下推自动机(DPDA)的升级,使得在弹出符号期间允许将读头返回到压入该符号时的位置。我们为该模型的 2-way 版本提供了一个线性时间模拟算法,该算法类似于著名的 S. Cook 的 2-way DPDA 线性时间模拟算法。
英文摘要:
We present a computational model for Parsing Expression Grammars (PEGs). The predecessor of PEGs top-down parsing languages (TDPLs) were discovered by A. Birman and J. Ullman in the 1960-s, B. Ford showed in 2004 that both formalisms recognize the same class named Parsing Expression Languages (PELs). A. Birman and J. Ullman established such important properties like TDPLs generate any DCFL and some non-context-free languages like $a^nb^nc^n$, a linear-time parsing algorithm was constructed as well. But since this parsing algorithm was impractical in the 60-s TDPLs were abandoned and then upgraded by B. Ford to PEGs, so the parsing algorithm was improved (from the practical point of view) as well. Now PEGs are actively used in compilers (eg., Python replaced LL(1)-parser with a PEG one) so as for text processing as well. In this paper, we present a computational model for PEG, obtain structural properties of PELs, namely proof that PELs contain Boolean closure of regular closure of DCFLs and PELs are closed over left concatenation with regular closure of DCFLs. We present an extension of the PELs class based on the extension of our computational model. Our model is an upgrade of deterministic pushdown automata (DPDA) such that during the pop of a symbol it is allowed to return the head to the position of the push of the symbol. We provide a linear-time simulation algorithm for the 2-way version of this model, which is similar to the famous S. Cook linear-time simulation algorithm of 2-way DPDA.
Synchronous Context-Free Grammars and Optimal Linear Parsing Strategies
Università di Firenze(佛罗伦萨大学);University of Rochester(罗切斯特大学);Università di Milano(米兰大学);Università di Roma Tor Vergata(罗马第二大学(托尔·维尔加塔));University of Padua(帕多瓦大学)
Describing the syntax of programming languages using conjunctive and Boolean grammars
Floyd的一个经典结果(“On the non-existence of a phrase structure grammar for ALGOL 60”,1962)指出,任何合理的程序设计语言的完整语法都不能用普通的形式语法(乔姆斯基的"context-free“)来描述。本文使用的语法扩展与合取和否定运算符,被称为合取语法和布尔语法,描述了一个简单的无类型的过程程序设计语言的一组格式良好的程序。一个完整的布尔文法,它定义了这样的概念,作为声明的变量和函数之前,他们的使用,构造和解释。使用用于布尔文法的广义LR解析算法,然后可以在时间上解析程序的长度$O(n^4)$,而另一已知算法允许子时间解析。接下来,它是如何将这种语法转换为一个明确的合取语法,平方时间解析。这显然成为完全由计算上可行的形式文法对程序设计语言的语法的第一个规范。
ETH Zürich(苏黎世联邦理工学院);Max Planck ETH Center for Learning Systems(马克斯·普朗克苏黎世联邦理工学院学习系统中心);University of Cambridge(剑桥大学);Johns Hopkins University(约翰斯·霍普金斯大学)