松鼠解析器:一种线性时间的PEG包rat解析器,能够处理左递归并具有最优的错误恢复能力
The Squirrel Parser: A Linear-Time PEG Packrat Parser Capable of Left Recursion and Optimal Error Recovery
AI总结:
松鼠解析器是一种能够高效处理左递归和错误恢复的线性时间PEG包rat解析器,通过创新算法和约束满足机制实现了最优性能。
摘要:
我们介绍了松鼠解析器,这是一种能够直接处理所有形式的左递归,并在存在任意数量的错误的情况下仍能保持输入长度线性时间复杂度的PEG包rat解析器。传统的递归下降解析器处理左递归的方法需要对文法进行重写或复杂的算法扩展。我们从第一性原理出发推导出一个最小的算法:通过逐个位置的状态跟踪进行循环检测,并通过从子递归框架到父递归框架的O(1)次LR循环通信实现。对于错误恢复,我们推导出一组四个公理和十二个约束,这些必须施加于最优错误恢复设计上,以确保完整性、正确性、性能的最优性和行为的直观性。我们利用约束满足机制来搜索所有可能性的空间,最终得到一个可以证明最优且稳健的错误恢复策略,该策略保持了完美的线性性能。
英文摘要:
We present the squirrel parser, a PEG packrat parser that directly handles all forms of left recursion with optimal error recovery, while maintaining linear time complexity in the length of the input even in the presence of an arbitrary number of errors. Traditional approaches to handling left recursion in a recursive descent parser require grammar rewriting or complex algorithmic extensions. We derive a minimal algorithm from first principles: cycle detection via per-position state tracking and $O(1)$-per-LR-cycle communication from descendant to ancestor recursion frames, and fixed-point search via iterative expansion. For error recovery, we derived a set of four axioms and twelve constraints that must be imposed upon an optimal error recovery design to ensure completeness, correctness, optimality of performance, and intuitiveness of behavior. We utilized a constraint satisfaction mechanism to search the space of all possibilities, arriving at a provably optimal and robust error recovery strategy that maintains perfect performance linearity.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。