用有原则的状态解析驯服上下文相关语言
Taming Context-Sensitive Languages with Principled Stateful Parsing
摘要:
历史上,真正的上下文相关解析很少应用于程序设计语言,这是由于其固有的复杂性。然而,许多主流编程和置标语言(C、Haskell、Python、XML等)都具有上下文敏感特性。这些特征传统上用ad-hoc代码(例如,自定义词法分析器),超出了解析理论的范围。当前的语法形式主义努力表达上下文敏感的功能。大多数解决方案缺乏上下文透明性:它们通过将上下文硬连接到整个语法中,使语法难以编写、维护和组合。相反,我们的方法上下文敏感的解析通过这样的想法,解析器可能会召回以前匹配的输入(或从中派生的数据),以作出解析决策。我们利用可变的解析状态来实现这种形式的召回。我们引入了有原则的状态解析作为一个新的事务性的纪律,使状态变化透明的解析机制,如回溯和memoization。为了加强这一原则,用户使用正式指定的原始状态操作来指定解析器。我们的解决方案是一个名为Autumn的解析库。我们说明我们的解决方案,实现一些实用的上下文敏感的语法功能,如显着的空白处理和命名空间分类。
英文摘要:
Historically, true context-sensitive parsing has seldom been applied to programming languages, due to its inherent complexity. However, many mainstream programming and markup languages (C, Haskell, Python, XML, and more) possess context-sensitive features. These features are traditionally handled with ad-hoc code (e.g., custom lexers), outside of the scope of parsing theory. Current grammar formalisms struggle to express context-sensitive features. Most solutions lack context transparency: they make grammars hard to write, maintain and compose by hardwiring context through the entire grammar. Instead, we approach context-sensitive parsing through the idea that parsers may recall previously matched input (or data derived therefrom) in order to make parsing decisions. We make use of mutable parse state to enable this form of recall. We introduce principled stateful parsing as a new transactional discipline that makes state changes transparent to parsing mechanisms such as backtracking and memoization. To enforce this discipline, users specify parsers using formally specified primitive state manipulation operations. Our solution is available as a parsing library named Autumn. We illustrate our solution by implementing some practical context-sensitive grammar features such as significant whitespace handling and namespace classification.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。