Is there a way to localize error messages from bison/flex?
Do bison and flex allow user to natively localize error messages? For example, I would like to translate following message: syntax error, unexpected NUMBER, expecting开发者_StackOverflow中文版 $end to other language and replace NUMBER/$end with something more human-readable.
Use yyerror and YY_USER_ACTION for additional data.
void yyerror(const char *s) {
sprintf(dummmy, "%s line %d col %d word '%s'\n", s, myline, mycolumn, yytext);
print_error(dummmy);
in the lex file
#define YY_USER_ACTION \
addme(yy_start, yytext); \
mycolumn += yyleng;\
if(*yytext == '\n') { myline++; mycolumn = 0; } else 0; \
精彩评论