bug-bison
[Top][All Lists]
Advanced

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

Info/Warning/Error Messages


From: Hans Aberg
Subject: Info/Warning/Error Messages
Date: Sun, 22 Oct 2000 17:16:33 +0200

It would probably not be to difficult to modify Flex/Bison to provide the
kind of information that the CW IDE expects for info/warning/error messages.

I made an implementation in Flex; the information is basically there, but
as Flex isn't designed to supply such information, so it needs to be
modified a little to support it.

I will renew the summary (in pseudo-C++) of what information one expects to
produce, with extra care taken to detail:

enum { Info, Warning, Error }   -- Type of message.
enum { General, Filespecific }  -- File-specific message or not
string message                  -- Message in words; may be multi-line.

For a general message, one just provides the information above. If the
message is file-specific, if one wants to identify place for the error, one
supplies the following:

class WhichFile {
  string filename;     -- Name of file (needed for finding OS file specifier).
  ...    filepointer;  -- Pointer to stream or file struct.
};
class Excerpt {
  string excerpt;       -- Excerpt of where the problem is; may be multiline.
  int position, length; -- Identifies the token character position, first = 0,
};                      -- and its length in this string.
class ErrorLocation {
  int linenumber;       -- Line number in the file; first = 1.
  int position, length; -- Character count in file, first = 0,
};                      -- and the length of the token.

The string "excerpt" could typically be the line where the failing token is
found. The safest way to find ErrorLocation.position would probably be to
use ostream::tellp() or equivalent (see below, though).

An implementation could be something like the following:

There is an extra variable yyline_number which is defined by the user. The
user must supply a notion of a line number count. Using Flex, this can be
done say by

int yyline_number = 1;
%}
line_separator  \n|\r|\r\n
...
%%
{line_separator}   { ++yyline_number; ... }
...

if one reads the files as binary, and wants to give a correct line count
for UNIX/Mac/DOS text files simultaneously.

If one decides that the string "excerpt" above should be the line on which
the error takes place, then one can try using

int yyline_number = 1;
char* yyline_start = 0;
char* yyline_offset = 0;
}%
line_separator  \n|\r|\r\n
...
%%
{line_separator}   { ++yyline_number; line_start = yy_cp; ... }
...
{any_other_rule}   { line_offset = yy_bp; ... }

Flex uses the variable yy_bp to point at the beginning of every lexeme
scan, and yy_cp points at the current character scanned, so when a full
scan has been identified, it sets yyleng = yy_cp - yy_bp, and yytext =
yy_bp.

This implementation is flawed though, because it does not work on the first
line. -- Thus, Flex ought to be modified to support this.
-- Also, for the ErrorLocation.position, one needs to keep track of the
character count from the start of the file. Again, in order to make this
correct, one would need to know something about Flex's internals (Flex may
scan ahead in a file so that ostream::tellp() and such stuff cannot in
general be expected to work), but it should otherwise not be overly
difficult to implement.

  Hans Aberg





reply via email to

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