help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

better error reporting with bison and flex


From: Guillaume Rousse
Subject: better error reporting with bison and flex
Date: Thu, 22 Jun 2006 15:13:54 +0200
User-agent: Thunderbird 1.5.0.4 (X11/20060618)

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]