paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Staged selective parser combinators

分阶段的选择性解析器组合子
ICFP 4(ICFP)2020匹配度 1/10 · 论文研究解析器组合子、selective functors 与 staging 编译优化,属于函数式编程和编译技术,与用户关注的静态分析、Agentic 程序、LLM 辅助形式化验证、浮点程序分析及贝叶斯程序分析均无直接关联。引用 20 inbox
Jamie Willis, Nicolas Wu, Matthew Pickering
dblp: 2026-09-10crossref: 2026-09-10

AI 速览

一句话:利用解析树、selective functors 和 staging,将解析器组合子编译为手写质量的解析器,并在 Parsley 库中实现。

解析器组合子兼具手写解析器的可控性和解析器生成器接近语法的高层表达,但历史上性能难以匹敌手写解析器。本文利用语法中的静态信息,将组合子语法表示为解析树,从而把解析器组合子编译为手写质量的解析器。为充分利用静态信息,作者放弃支持会生成动态结构的 monadic 计算,转而用 selective functors 恢复部分能力,并通过 staging 对解析树进行部分求值。该方法在 Parsley 库中实现,表明组合子可被编译成高性能解析器。

问题
解析器组合子易于组合,但性能通常不及手写解析器;此外,monadic 组合子会生成动态结构,阻碍基于语法的静态优化。
方法
把组合子语法表示为树以利用静态信息,放弃 monad,使用 selective functors 补足功能,并通过 staging 对解析树进行部分求值,将组合子编译为手写质量的解析器。
评估
该技术实现于 Parsley 库中,目标是让解析器组合子达到手写解析器的性能质量;摘要未给出具体基准测试数据。
原文摘要(Abstract)

Parser combinators are a middle ground between the fine control of hand-rolled parsers and the high-level almost grammar-like appearance of parsers created via parser generators. They also promote a cleaner, compositional design for parsers. Historically, however, they cannot match the performance of their counterparts. This paper describes how to compile parser combinators into parsers of hand-written quality. This is done by leveraging the static information present in the grammar by representing it as a tree. However, in order to exploit this information, it will be necessary to drop support for monadic computation since this generates dynamic structure. Selective functors can help recover lost functionality in the absence of monads, and the parser tree can be partially evaluated with staging. This is implemented in a library called Parsley.

链接与引用

DOI 原文 · PDF(开放获取) · DBLP

BibTeX
@article{WillisWP20,
  title = {Staged selective parser combinators},
  author = {Jamie Willis and Nicolas Wu and Matthew Pickering},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {4},
  number = {ICFP},
  year = {2020},
  doi = {10.1145/3409002}
}