面向解析表达式中自动错误恢复的研究
Towards Automatic Error Recovery in Parsing Expression
AI总结:
本文提出一种自动为解析表达式文法标注标签并生成恢复表达式的算法,通过在Titan语言解析器上的实验证明,仅需少量人工干预即可为大多数备选分支互不相交的PEGs构建错误恢复解析器。
摘要:
错误恢复是应集成到集成开发环境(IDE)中的解析器的一项基本特性,即使对于语法无效的程序,解析器也必须构建抽象语法树(AST),以便提供诸如自动重构和代码补全等功能。解析表达式文法(PEGs)是一种形式化方法,它使用受限的回溯形式自然地描述递归自顶向下的解析器。带标签的失败是PEGs的一种保守扩展,它为PEG解析器增加了错误报告机制,这些标签还可以与恢复表达式关联,从而同时成为一种错误恢复机制。这些表达式可以利用PEGs的全部表达能力来从语法错误中恢复。手动为大型文法标注标签和恢复表达式可能很困难。在这项工作中,我们提出了一种算法,可以自动为PEG标注标签,并构建相应的恢复表达式。我们通过为Titan编程语言的解析器添加错误恢复来评估该算法。结果表明,只需少量人工干预,我们的算法就可以用于为大多数备选分支互不相交的PEGs生成具有错误恢复能力的解析器。
英文摘要:
Error recovery is an essential feature for a parser that should be plugged in Integrated Development Environments (IDEs), which must build Abstract Syntax Trees (ASTs) even for syntactically invalid programs in order to offer features such as automated refactoring and code completion. Parsing Expressions Grammars (PEGs) are a formalism that naturally describes recursive top-down parsers using a restricted form of backtracking. Labeled failures are a conservative extension of PEGs that adds an error reporting mechanism for PEG parsers, and these labels can also be associated with recovery expressions to also be an error recovery mechanism. These expressions can use the full expressivity of PEGs to recover from syntactic errors. Manually annotating a large grammar with labels and recovery expressions can be difficult. In this work, we present an algorithm that automatically annotates a PEG with labels, and builds their corresponding recovery expressions. We evaluate this algorithm by adding error recovery to the parser of the Titan programming language. The results shown that with a small amount of manual intervention our algorithm can be used to produce error recovering parsers for PEGs where most of the alternatives are disjoint.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。