views:

17

answers:

1

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 $end to other language and replace NUMBER/$end with something more human-readable.

A: 

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; \
acidzombie24