Packrat解析:简单,强大,懒惰,线性时间
Packrat Parsing: Simple, Powerful, Lazy, Linear Time
摘要:
Packrat解析是一种在惰性函数式程序设计语言中实现解析器的新技术。packrat解析器提供了自顶向下解析的能力和灵活性,具有回溯和无限的前瞻性,但仍然保证线性解析时间。任何由LL(k)或LR(k)语法定义的语言都可以被packrat解析器识别,除了传统的线性时间算法不支持的许多语言之外。这种额外的能力简化了对常见句法习惯用法的处理,例如广泛但麻烦的最长匹配规则,使复杂的消歧策略(例如句法和语义谓词)的使用成为可能,提供更好的语法组合属性,并允许词法分析无缝地集成到解析中。然而,尽管它的强大,packrat解析共享相同的简单性和优雅的递归下降解析;事实上,转换一个回溯递归下降解析器到线性时间packrat解析器往往只涉及一个相当简单的结构变化。本文介绍了packrat解析非正式的,重点是它在实际应用中的使用,并探讨了它的优点和缺点相对于更传统的替代品。
英文摘要:
Packrat parsing is a novel technique for implementing parsers in a lazy functional programming language. A packrat parser provides the power and flexibility of top-down parsing with backtracking and unlimited lookahead, but nevertheless guarantees linear parse time. Any language defined by an LL(k) or LR(k) grammar can be recognized by a packrat parser, in addition to many languages that conventional linear-time algorithms do not support. This additional power simplifies the handling of common syntactic idioms such as the widespread but troublesome longest-match rule, enables the use of sophisticated disambiguation strategies such as syntactic and semantic predicates, provides better grammar composition properties, and allows lexical analysis to be integrated seamlessly into parsing. Yet despite its power, packrat parsing shares the same simplicity and elegance as recursive descent parsing; in fact converting a backtracking recursive descent parser into a linear-time packrat parser often involves only a fairly straightforward structural change. This paper describes packrat parsing informally with emphasis on its use in practical applications, and explores its advantages and disadvantages with respect to the more conventional alternatives.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。