【24h】

Parsing with Derivatives

机译:解析导数

获取原文
获取原文并翻译 | 示例

摘要

We present a functional approach to parsing unrestricted context-free grammars based on Brzozowski's derivative of regular expressions. If we consider context-free grammars as recursive regular expressions, Brzozowski's equational theory extends without modification to context-free grammars (and it generalizes to parser combi-nators). The supporting actors in this story are three concepts familiar to functional programmers-laziness, memoization and fixed points; these allow Brzozowski's original equations to be transliterated into purely functional code in about 30 lines spread over three functions. Yet, this almost impossibly brief implementation has a drawback: its performance is sour-in both theory and practice. The culprit? Each derivative can double the size of a grammar, and with it, the cost of the next derivative. Fortunately, much of the new structure inflicted by the derivative is either dead on arrival, or it dies after the very next derivative. To eliminate it, we once again exploit laziness and memoization to transliterate an equational theory that prunes such debris into working code. Thanks to this compaction, parsing times become reasonable in practice. We equip the functional programmer with two equational theories that, when combined, make for an abbreviated understanding and implementation of a system for parsing context-free languages.
机译:我们提出了一种基于Brzozowski正则表达式的派生函数来解析不受限制的上下文无关文法的功能方法。如果我们将无上下文语法视为递归正则表达式,则Brzozowski的方程式理论无需对无上下文语法进行修改即可扩展(并且泛化为解析器组合器)。这个故事中的支持者是函数程序员熟悉的三个概念:懒惰,记忆和不动点。这些使Brzozowski的原始方程式可以分解成三个函数,分布在大约30行中,转化为纯函数代码。但是,这种几乎不可能实现的简短实现有一个缺点:在理论和实践上它的性能都是糟糕的。罪魁祸首?每个导数可以使语法的大小加倍,从而使下一个导数的成本增加一倍。幸运的是,派生类所带来的许多新结构要么在到达时就死了,要么在下一个派生类之后死了。为了消除这种情况,我们再次利用懒惰和记忆来将方程式理论音译成将这些碎片修剪成工作代码的方式。由于这种压缩,在实践中解析时间变得合理了。我们为函数式程序员提供了两个方程式理论,这些方程式理论相结合可简化对上下文无关语言的系统的理解和实现。

著录项

相似文献

  • 外文文献
  • 中文文献
  • 专利
获取原文

客服邮箱:kefu@zhangqiaokeyan.com

京公网安备:11010802029741号 ICP备案号:京ICP备15016152号-6 六维联合信息科技 (北京) 有限公司©版权所有
  • 客服微信

  • 服务号