arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1905.02145cs.PLcs.FL
收藏

表达式语法分析中的自动语法错误报告和恢复

Automatic Syntax Error Reporting and Recovery in Parsing Expression Grammars

Sérgio Queiroz de Medeiros, Gilney de Azevedo Alvez Junior, Fabio Mascarenhas

摘要:

错误恢复是解析器的一个基本功能,它应该插入集成开发环境(IDE)中,即使对于语法无效的程序,IDE也必须构建抽象树(AST),以便提供自动重构和代码完成等功能。解析表达式语法(Parsing Expressions Grammars,PEG)是一种形式主义,它自然地描述了使用受限形式的回溯的递归自顶向下解析器。标记的失败是PEG的保守扩展,它为PEG解析器添加了错误报告机制,这些标签也可以与恢复表达式相关联,以提供错误恢复机制。这些表达式可以使用PEG的完整表达性来从语法错误中恢复。使用标签和恢复表达式手动注释大型语法可能很困难。在这项工作中,我们提出了两种方法,标准和独特的,自动注释PEG标签,并建立相应的恢复表达式。标准方法以类似于手动注释的方式注释语法,但它可能会错误地插入标签,而唯一方法在注释语法时更加保守,并且不会错误地插入标签。我们评估这两种方法,使用它们来生成错误恢复解析器的四个程序设计语言:泰坦,C,Pascal和Java。在我们的评估中,使用标准方法生成的解析器,在手动干预以删除错误添加的标签后,对每种语言中至少70%的文件进行了可接受的恢复。反过来,通过Unique方法生成的解析器的可接受恢复率在41%到76%之间,而不需要人工干预。

英文摘要:

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 provide 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 two approaches, Standard and Unique, to automatically annotate a PEG with labels, and to build their corresponding recovery expressions. The Standard approach annotates a grammar in a way similar to manual annotation, but it may insert labels incorrectly, while the Unique approach is more conservative to annotate a grammar and does not insert labels incorrectly. We evaluate both approaches by using them to generate error recovering parsers for four programming languages: Titan, C, Pascal and Java. In our evaluation, the parsers produced using the Standard approach, after a manual intervention to remove the labels incorrectly added, gave an acceptable recovery for at least 70% of the files in each language. By it turn, the acceptable recovery rate of the parsers produced via the Unique approach, without the need of manual intervention, ranged from 41% to 76%.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑