[Top][All Lists]

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

Re: Bison-1.28: Doc Typo, Misc Bugs

From: Hans Aberg
Subject: Re: Bison-1.28: Doc Typo, Misc Bugs
Date: Wed, 4 Oct 2000 15:16:24 +0200

At 10.11 +0200 0-10-04, Akim Demaille wrote:
>| -- About the simple parser, I noticed it was not overly difficult to
>| compile it as C++ code.
>Nope, indeed.  I do that myself.  See also a project named CMix where
>they have a Bison parser used in a C++ project.
>        C-Mix
>        C-Mix is an automatic partial evaluator for the ISO/ANSI C
>        language. It transforms generic programs into more efficient,
>        specialized versions. For an introduction, read the short
>        paper C-Mix: Making Easily Maintainable C-Programs run Fast.
>        http://www.diku.dk/research-groups/topps/activities/cmix/

Thank you for the tip.

>Hm, OK, I had not realized YYLTYPE was not defaulted in hairy as it is
>in simple.


> Another rather surprising thing about hairy is that
>yyerror is a variable there!

Well, that's hairy. :-) -- I noticed it too.

>| >That's interesting: what the layout for such error messages?
>| typedef struct CWMessageRef
>| {
>|   CWFileSpec sourcefile;      /* file containing error                    */
>|   long       linenumber;      /* error linenumber in file                 */
>|   short      tokenoffset;     /* offset into errorline of token underline */
>|   short      tokenlength;     /* length of error token to be underlined   */
>|   long       selectionoffset; /* start of error for text selection        */
>|   long       selectionlength; /* length of error for text selection       */
>| } CWMessageRef;
>| The CWFileSpec is the file spec struct used on the specific platform
>| (MacOS, Windows or UNIX). The IDE will underline the token indicated by
>| (tokenoffset, tokenlength) str2 of the in the messagewindow. In the file in
>| question, on the line linenumber, it will highlight the area indicated by
>| (selectionoffset, selectionlength.
>How does it work for multiline symbols?

There is no problem in displaying several lines in each of the two strings
(by the use of '\n' in the strings): Then str1, str2 are displayed as two
segments or paragraphs on top of each other. Actually, this is how it works
if one say use the --help option in my port. For some type of information,
it can be suitable to use multilines, if they belong to the one and same

If type of information specific to a location in a file (usually the file
being compiled containing a failing token) should have its own IDE message,
as then the user can click on the window and get the location displayed.

>| When sending a message one also has an enum of the form
>|     enum {
>|         Info,
>|         Warning,
>|         Error
>|     };
>| and two strings str1, str2, the first and second line of the message. If
>| one does not want some or any of the CWMessageRef data, a field or the
>| whole of it, or any of the two strings, one sets whatever excluded to 0 (or
>| NULL). A typical message will look like
>|     <>|<Warning:>|<Error:> str1
>|     <filename> <linenumber>: str2
>| If one clicks on the entry, the file with its underline/selection will pop
>| open.
>| For example:
>| Warning : Bison Compiler-Compiler
>| rpcalc.y line 43   symbol lines is used, but is not defined as a token
>|                                    ----
>|                                    ^
>| Underlining displayed by the IDE --|
>| The idea is that the first line str1 should be a description of the
>| problem, and the second str2 a segment of the failing code, where the
>| failing token is pinpointed. Here is a C-error:
>| Error   : undefined identifier 'foo'
>| Bison Plugin.c line 244   cwMessageRef.tokenoffset = foo;
>|                                                      ---
>| And the part from the file "Bison Plugin.c" window will look like:
>|         ....
>|         cwMessageRef.linenumber = lineno;
>| =>      cwMessageRef.tokenoffset = |foo|;
>|         cwMessageRef.tokenlength = 0;
>|         ...
>| where I have simulated the displayed selection using |...|.
>Actually my question was more `how should a tool display the location
>of symbols to be understood by your IDE'.  IIUC, it is not a matter of
>printing an error msg this or that way, but it's actually by filling a

The idea is that compiler picks out a segment of what it just have read and
puts that into str2, giving the numbers (tokenoffset, tokenlength) to
identify the failing token (or whatever) in that string str2.

The numbers (linenumber, selectionoffset, selectionlength) refer to the
file in question, but should normally identify the same token as in str2.
So I figure that normally tokenlength = selectionlength, whereas
tokenoffset will be diminished with what one stripped out of the line with
line number "linenumber" in order to get str2.

The source file pointer cannot be given by the compiler in a platform
independent manner; it is gotten from the IDE by a special call. The
compiler can though provide the information whether this pointer should be
NULL or not, meaning that the information is not file specific or not.

Then normally str1 will be the actual message, describing in words what the
problem is.

A summary of the data needed would be (in pseudo C++):

enum { Info, Warning, Error }   -- Type of message.
enum { General, Filespecific }  -- Filespecific message or not
string message                  -- Message in words; may be multiline.
class Excerpt {
  string excerpt;               -- Excerpt of where the problem is.
  int position, length;         -- Identifying the token position and its
};                              -- length in this string for underlining.
class ErrorLocation {
  int linenumber, lineposition, length; -- identifying the position in the

The above does not include the file, as that was wellknown, but in order to
handle the case where several files are opened, I would add:
class WhichFile {
  string filename;     -- Name of file
  ...    filepointer;  -- Pointer to stream or file struct.

It is important to include the filename, because the IDE may use non-C/C++
platform specific file descriptors, and then one can use the name of the
file to do a search in via the IDE in order to get that platform specific
file descriptor.

  Hans Aberg

reply via email to

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