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.


翻译:词法分析器和语法分析器通常分别定义,并通过 token 流连接。这种分离式定义对于模块化非常重要,并减少了解析歧义的可能性。然而,将 token 具体化为数据结构并对其进行 case 切换会带来性能开销。我们展示了如何融合分别定义的词法分析器和语法分析器,从而在不损害模块化或增加歧义的情况下显著提升性能。我们提出了 Greibach 范式的确定性变体,该变体确保仅需单个 lookahead token 即可实现确定性解析,并使融合过程极为简洁,同时证明了将上下文无关表达式规范化为确定性范式的语义保持性。我们的分阶段解析器组合子库 flap 提供了标准接口,但能够生成专门的免 token 代码,在一系列基准测试中,其运行速度比 ocamlyacc 快两到六倍。

0
下载
关闭预览

相关内容

词法分析(英语:lexical analysis)是计算机科学中将字符序列转换为单词(Token)序列的过程。 词法分析(lexical analysis)包括汉语分词和词性标注两部分。和大部分西方语言不同,汉语书面语词语之间没有明显的空格标记,文本中的句子以字串的形式出现。 因此汉语自然语言处理的首要工作就是要将输入的字串切分为单独的词语,然后在此基础上进行其他更高级的分析,这一步骤称为分词(word segmentation 或tokenization)。除了 分词,词性标注也通常认为是词法分析的一部分。给定一个切好词的句子,词性标注的目的是为每一个词赋予一个类别,这个类别称为词性标记(part-of-speech tag),比如,名词(noun)、动词(verb)、形容词(adjective)等。
专知会员服务
19+阅读 · 2020年9月6日
强化学习最新教程,17页pdf
专知会员服务
182+阅读 · 2019年10月11日
[综述]深度学习下的场景文本检测与识别
专知会员服务
78+阅读 · 2019年10月10日
机器学习入门的经验与建议
专知会员服务
94+阅读 · 2019年10月10日
【哈佛大学商学院课程Fall 2019】机器学习可解释性
专知会员服务
105+阅读 · 2019年10月9日
VCIP 2022 Call for Demos
CCF多媒体专委会
1+阅读 · 2022年6月6日
Hierarchically Structured Meta-learning
CreateAMind
27+阅读 · 2019年5月22日
已删除
科学网
60+阅读 · 2018年2月9日
【CNN】一文读懂卷积神经网络CNN
产业智能官
18+阅读 · 2018年1月2日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2013年12月31日
国家自然科学基金
0+阅读 · 2013年12月31日
国家自然科学基金
2+阅读 · 2013年12月31日
国家自然科学基金
0+阅读 · 2012年12月31日
国家自然科学基金
0+阅读 · 2012年12月31日
国家自然科学基金
4+阅读 · 2012年12月31日
国家自然科学基金
0+阅读 · 2012年12月31日
国家自然科学基金
0+阅读 · 2011年12月31日
国家自然科学基金
0+阅读 · 2009年12月31日
Arxiv
0+阅读 · 2023年5月30日
Arxiv
0+阅读 · 2023年5月26日
VIP会员
最新内容
《通过小型无人机系统将情报能力“作战化”》
专知会员服务
0+阅读 · 23分钟前
消耗优势:美军的“精确规模化”概念
专知会员服务
7+阅读 · 6月15日
《离线语言支持系统:面向空战战术决策》
专知会员服务
8+阅读 · 6月15日
俄乌战场地面机器人如何改写战争规则
专知会员服务
9+阅读 · 6月14日
《无人水面艇文献综述与结构设计》135页
专知会员服务
16+阅读 · 6月13日
相关VIP内容
专知会员服务
19+阅读 · 2020年9月6日
强化学习最新教程,17页pdf
专知会员服务
182+阅读 · 2019年10月11日
[综述]深度学习下的场景文本检测与识别
专知会员服务
78+阅读 · 2019年10月10日
机器学习入门的经验与建议
专知会员服务
94+阅读 · 2019年10月10日
【哈佛大学商学院课程Fall 2019】机器学习可解释性
专知会员服务
105+阅读 · 2019年10月9日
相关资讯
VCIP 2022 Call for Demos
CCF多媒体专委会
1+阅读 · 2022年6月6日
Hierarchically Structured Meta-learning
CreateAMind
27+阅读 · 2019年5月22日
已删除
科学网
60+阅读 · 2018年2月9日
【CNN】一文读懂卷积神经网络CNN
产业智能官
18+阅读 · 2018年1月2日
相关基金
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2013年12月31日
国家自然科学基金
0+阅读 · 2013年12月31日
国家自然科学基金
2+阅读 · 2013年12月31日
国家自然科学基金
0+阅读 · 2012年12月31日
国家自然科学基金
0+阅读 · 2012年12月31日
国家自然科学基金
4+阅读 · 2012年12月31日
国家自然科学基金
0+阅读 · 2012年12月31日
国家自然科学基金
0+阅读 · 2011年12月31日
国家自然科学基金
0+阅读 · 2009年12月31日
Top
微信扫码咨询专知VIP会员