如何从法/ yacc的更多解析错误的信息? [英] How to get more parse error information from lex / yacc?
问题描述
如何从法/ yacc的更多解析错误信息?
How to get more parse error information from lex / yacc?
目前在lex文件我使用:
Currently in the lex file I am using:
int yyerror(const char *msg)
{
fprintf(stderr, "Parse error: %s\n", msg);
return 0;
}
但是,当我运行我的程序的yyerror输出空白消息。我尝试添加yylineno和yytext中以YYERROR但这些原因编译错误。我尝试添加%错误详细的YACC文件
%选项调试的文件法但这些作出消息没有什么区别。
But when I run my program yyerror outputs a blank message. I tried adding yylineno and yytext to yyerror but these cause compilation errors. I tried adding "%error-verbose" to the yacc file and "%option debug" to the lex file but these made no difference to the message.
我也注意到这不过输出yyparse支架:'{'从我试图解析文件,我不知道这样做的意义
I did notice however that yyparse outputs a bracket: '{' from the file I am trying to parse, I don't know the significance of this.
我使用win_flex和win_bison。
I am using win_flex and win_bison.
推荐答案
这在很大程度上是在的官方野牛手动当它展示了如何使用的yyerror
来得到改进的错误消息。
Much of this is described in the official bison manual when it shows how to use yyerror
to get improved error messages.
在特别的,它建议您使用%,在野牛声明部分详细
定义parse.error得到增强的错误消息。
In particular, it suggests you use %define parse.error verbose
in the Bison declarations section to get enhanced error messages.
这篇关于如何从法/ yacc的更多解析错误的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!