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

解析表达式文法的错误恢复

Syntax Error Recovery in Parsing Expression Grammars

Sérgio Medeiros, Fabio Mascarenhas

摘要:

解析表达式语法(Parsing Expression Grammars,PEG)是一种用于描述具有回溯功能的自顶向下解析器的形式主义。由于PEG不提供良好的错误恢复机制,基于PEG的解析器通常不能从输入中的语法错误中恢复,或者使用特定于实现的特性从语法错误中恢复。缺乏正确的错误恢复使得PEG解析器不适合与集成开发环境(IDE)一起使用,IDE甚至需要为不完整的语法无效的程序构建语法树。我们提出了一个保守的扩展,标记失败的PEG的基础上,增加了一个语法错误恢复机制的PEG。此扩展将恢复表达式与标签相关联,其中标签现在不仅报告语法错误,而且还使用此恢复表达式到达输入和恢复解析中的同步点。我们给这个恢复机制的PEG的操作语义,并使用这样的语义的基础上建立一个强大的解析器的Lua语言的实现。我们评估这个解析器的有效性,单独和比较Lua解析器与自动错误恢复生成的ANTLR,一个流行的解析器生成器。

英文摘要:

Parsing Expression Grammars (PEGs) are a formalism used to describe top-down parsers with backtracking. As PEGs do not provide a good error recovery mechanism, PEG-based parsers usually do not recover from syntax errors in the input, or recover from syntax errors using ad-hoc, implementation-specific features. The lack of proper error recovery makes PEG parsers unsuitable for using with Integrated Development Environments (IDEs), which need to build syntactic trees even for incomplete, syntactically invalid programs. We propose a conservative extension, based on PEGs with labeled failures, that adds a syntax error recovery mechanism for PEGs. This extension associates recovery expressions to labels, where a label now not only reports a syntax error but also uses this recovery expression to reach a synchronization point in the input and resume parsing. We give an operational semantics of PEGs with this recovery mechanism, and use an implementation based on such semantics to build a robust parser for the Lua language. We evaluate the effectiveness of this parser, alone and in comparison with a Lua parser with automatic error recovery generated by ANTLR, a popular parser generator.

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

↑