Hello. I'm trying for two days now to produce better output messages in case of parsing failure. I'm using flex + bison for a standard (non-reentrant) parser.
I've had to redefine YY_INPUT in scanner.l, as I'm parsing small, line-based messages, and default version was blocking: #define YY_INPUT(buf,result,max_size) \ if (yy_current_buffer->yy_is_interactive ) { \ int c = '*', n; \ for (n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n) \ buf[n] = (char) c; \ if (c == '\n') \ buf[n++] = (char) c; \ if (c == EOF && ferror( yyin )) \ YY_FATAL_ERROR("input in flex scanner failed"); \ result = n; \ } else { \ if ((fgets(buf, max_size, yyin) == NULL) && ferror(yyin)) \ YY_FATAL_ERROR("input in flex scanner failed"); \ result = strlen(buf); \ } >From flex and bison manuals, I've understood the following informations: - yyerror function receive a simple string error message, such as "syntax error" - using %error-verbose bison directive make this error message a bit more verbose, such as "syntax error, unexpected VALUE_WORD, expecting ARR1D_STOP" - defining %yylineno flex directive make input line also available as global variable yylineno from yy_error - defining %locations bison directive make global variable yylloc available, with four fields defining first and last lines and columns where error occurs However, all I could achieve by combining those values was something as: syntax error, unexpected VALUE_WORD, expecting ARR1D_STOP Location: line 7, columns 0-0 Which is really not meaningful for user :/ I'd prefer to at least display current line, and avoid refering to internal grammar symbols. I've searched mailing-list without success. I also read generated scanner.c file, in order to access yy_current_buffer object with the proper character range, but without success. -- Guillaume Rousse Projet Estime, INRIA Domaine de Voluceau Rocquencourt - B.P. 105 78153 Le Chesnay Cedex - France _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison