arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2304.05276cs.PL
收藏

flap:一种融合词法分析的确定性解析器

flap: A Deterministic Parser with Fused Lexing

Jeremy Yallop, Ningning Xie, Neel Krishnaswami

AI总结:

本文提出 flap 解析器组合子库,通过确定性格雷巴赫范式将词法分析与解析融合为免令牌代码,在保持模块化且不增加歧义的前提下,使解析速度比 ocamlyacc 快二到六倍。

摘要:

词法分析器与解析器通常被分别定义,并通过令牌流进行连接。这种分离式定义对于模块化至关重要,并能降低解析歧义的可能性。然而,将令牌具体化为数据结构并对令牌进行分支切换会带来性能开销。我们展示了如何将分别定义的词法分析器与解析器进行融合,在不妨碍模块化、不增加歧义的前提下大幅提升性能。我们提出了格雷巴赫范式的一种确定性变体,该变体仅需一个前瞻令牌即可保证确定性解析,并使融合变得异常简单;同时我们证明了将上下文无关表达式规范化到该确定性范式是保持语义的。我们的分阶段解析器组合子库 flap 提供了标准接口,但能生成专门的免令牌代码,在一系列基准测试上运行速度比 ocamlyacc 快二到六倍。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑