bison 和 flex 是否允许用户本地化错误消息?例如,我想翻译以下消息:语法错误,意外的 NUMBER,期望 $end为其他语言,并将 NUMBER/$end 替换为更易于阅读的内容。
问问题
266 次
1 回答
1
使用 yyerror 和 YY_USER_ACTION 获取其他数据。
void yyerror(const char *s) {
sprintf(dummmy, "%s line %d col %d word '%s'\n", s, myline, mycolumn, yytext);
print_error(dummmy);
在 lex 文件中
#define YY_USER_ACTION \
addme(yy_start, yytext); \
mycolumn += yyleng;\
if(*yytext == '\n') { myline++; mycolumn = 0; } else 0; \
于 2010-07-26T02:44:57.733 回答