help-bison
[Top][All Lists]
Advanced

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

Re: Location tracking (Was: Redifining yyltype)


From: Laurence Finston
Subject: Re: Location tracking (Was: Redifining yyltype)
Date: Wed, 14 Apr 2004 13:35:43 +0200 (MEST)

Hello,

I'm using locations in my parser and I haven't had any unsolvable
problems so far.

I've redefined `YYLTYPE' as follows:
#define YYLTYPE LDF_LOCATION_TYPE

`LDF_LOCATION_TYPE' is a `struct' with a constructor that initializes
the data elements (I'm using C++).

I've had to redefine `YYLOC_DEFAULT' as follows:
#define YYLOC_DEFAULT(Current, Rhs, N) /* Do nothing.  */

I can't remember exactly what error it produced before, but it had to
do with data members of `YYLTYPE' with names from the default version.
It's probably possible to redefine `YYLOC_DEFAULT' to get it to behave
the way I want it to, but I haven't gotten around to it yet.
It may not be necessary, depending on how much I use locations in the
parser as opposed to the scanner.

It was also necessary to write the new definition of `YYLTYPE' to an
additional header file, because Bison does not write it to the header
file it generates from the Bison input file.  I use CWEB, so I have
`ctangle' generate the extra header file.  It would, of course, be
possible to just put the definition in an additional header file by
hand.  This header file must be included in the files that depend on
it _before_ the header file generated by Bison.

`LDF_LOCATION_TYPE' has an `unsigned long' named `position' in
addition to the data members for the first and last lines and first
and last columns.  I plan to use this for keeping track of the
position in the input files for use with `fseek()'.  This is so that I
can print out lines of context in my error messages, similar to the way
TeX and Metafont do.
This isn't possible with the default `YYLTYPE'.

I did find that I couldn't get Flex to work the way I wanted it to and
wrote my own `yylex()'.  My scanner and parser must be reentrant;
on another project, where this wasn't the case, I was able to use Flex.

Laurence Finston
http://wwwuser.gwdg.de/~lfinsto1

On Mon, 12 Apr 2004, Henrik Sorensen wrote:

>
> Are there any particuliar reasons for concern when using the location tracking
> ?
> Or is nobody actually using this feature ?
>
> Henrik
>
>





reply via email to

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