paperbot · PL 论文追踪

全部论文 待读 收藏

P2 flap: A Deterministic Parser with Fused Lexing

flap:一种融合词法分析的确定性解析器
PLDI 7(PLDI)2023匹配度 2/10 · 该论文属于编程语言/编译器领域的解析器性能优化,提出确定性 Greibach 范式和词法语法融合,但不涉及用户的 PL↔AI、静态分析、浮点程序分析或贝叶斯程序分析等核心方向。虽然来自 PL 领域并兼具形式化与工程实现,但与具体研究画像交集很小。引用 10 inbox
Jeremy Yallop, Ningning Xie, Neel Krishnaswami
crossref: 2026-09-10

AI 速览

一句话:提出确定性 Greibach 范式,将词法与语法分析融合,实现无 token 流的高效确定性解析器组合子库 flap。

词法器和解析器通常分开定义、通过 token 流连接,这种分离有利于模块化并减少解析歧义,但物化 token 数据结构并对其做 case 分支会带来开销。本文提出一种确定性的 Greibach 范式变体,保证仅用单个 token 的前瞻即可进行确定性解析,并使词法与语法分析的融合变得异常简单;作者证明将上下文无关表达式规范化为该确定范式是保语义的。基于此实现了分阶段的解析器组合子库 flap:它对外提供标准接口,但生成特化的、无 token 的代码。在多个基准测试上,flap 生成的解析器比 ocamlyacc 快 2 到 6 倍。

问题
传统词法分析与语法分析分开定义并以 token 流连接,虽保证模块化与低歧义,但 token 的物化和分支切换带来显著运行时开销。
方法
提出确定性的 Greibach 范式变体,保证单 token 前瞻的确定性解析并使词法与语法融合简单化,形式化证明该规范化保语义;据此实现分阶段解析器组合子库 flap,生成特化的无 token 代码。
评估
在多个基准上对比 ocamlyacc,flap 生成的解析器运行速度快 2 到 6 倍,同时保持标准接口与模块化。
原文摘要(Abstract)

Lexers and parsers are typically defined separately and connected by a token stream. This separate definition is important for modularity and reduces the potential for parsing ambiguity. However, materializing tokens as data structures and case-switching on tokens comes with a cost. We show how to fuse separately-defined lexers and parsers, drastically improving performance without compromising modularity or increasing ambiguity. We propose a deterministic variant of Greibach Normal Form that ensures deterministic parsing with a single token of lookahead and makes fusion strikingly simple, and prove that normalizing context free expressions into the deterministic normal form is semantics-preserving. Our staged parser combinator library, flap, provides a standard interface, but generates specialized token-free code that runs two to six times faster than ocamlyacc on a range of benchmarks.

链接与引用

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

BibTeX
@article{paperbot1989,
  title = {flap: A Deterministic Parser with Fused Lexing},
  author = {Jeremy Yallop and Ningning Xie and Neel Krishnaswami},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {7},
  number = {PLDI},
  year = {2023},
  doi = {10.1145/3591269}
}