Generating LR syntax error messages from examples

Generating LR syntax error messages from examples
复制标题

从示例生成 LR 语法错误消息

DOI:
10.1145/937563.937566
复制
发表时间:
2003
期刊:
ACM Trans. Program. Lang. Syst.
影响因子:
--
通讯作者:
C. Jeffery
C. Jeffery
中科院分区:
--
文献类型:
--
作者:
C. Jeffery

文献摘要

被引文献

相似文献

LR解析器生成器功能强大且易于理解,但它们生成的解析器不适合提供良好的错误消息。许多编译器会对源语法进行大量修改,以生成有用的语法错误消息。在出错时解释解析状态(和输入标记)是一种非侵入性的替代方法,它不会在错误消息生成过程中影响错误恢复机制。不幸的是,语法的每一个变化都可能显著地改变从解析状态到诊断消息的映射,从而产生维护问题。Merr是一个允许编译器编写者通过示例将诊断消息与语法错误相关联的工具,避免了向语法添加错误产生式或解释整数解析状态的需要。根据错误和消息的规范,Merr在每个示例错误上运行编译器以获得相关的解析状态和输入标记,并生成一个yyerror()函数,该函数将解析状态和输入标记映射到诊断消息。Merr在基于LR的编译器中启用有用的语法错误消息,这种方式在语法更改时是健壮的。
LR parser generators are powerful and well-understood, but the parsers they generate are not suited to provide good error messages. Many compilers incur extensive modifications to the source grammar to produce useful syntax error messages. Interpreting the parse state (and input token) at the time of error is a nonintrusive alternative that does not entangle the error recovery mechanism in error message production. Unfortunately, every change to the grammar may significantly alter the mapping from parse states to diagnostic messages, creating a maintenance problem.Merr is a tool that allows a compiler writer to associate diagnostic messages with syntax errors by example, avoiding the need to add error productions to the grammar or interpret integer parse states. From a specification of errors and messages, Merr runs the compiler on each example error to obtain the relevant parse state and input token, and generates a yyerror() function that maps parse states and input tokens to diagnostic messages. Merr enables useful syntax error messages in LR-based compilers in a manner that is robust in the presence of grammar changes.