help-bison
[Top][All Lists]
Advanced

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

Re: location tracking with empty RHS.


From: Hans Aberg
Subject: Re: location tracking with empty RHS.
Date: Sat, 5 Apr 2003 10:29:28 +0200

At 15:18 +0900 2003/04/05, Tanaka Akira wrote:
>Hi.  I have a question about location tracking with empty RHS.
>
>Bison uses YYLLOC_DEFAULT to track locations.
>By default, it is defined as follows.
>
>     #define YYLLOC_DEFAULT(Current, Rhs, N)          \
>       Current.first_line   = Rhs[1].first_line;      \
>       Current.first_column = Rhs[1].first_column;    \
>       Current.last_line    = Rhs[N].last_line;       \
>       Current.last_column  = Rhs[N].last_column;
>
>But what's happen when N = 0 which is caused by empty RHS?

Perhaps Akim Demaille can come up with a more "GNU official" answer later
(I am not a GNUer).

The Bison location tracking stuff is something that came with the original
Bison written by Corbett, but has as such never been supported. It is just
there because it always been and nobody removed or altered it.

So you can't expect anything much of it in its current form. For example,
the rule above identifies the region of the grammar variable in the parsed
text. In an error generating device, it is more useful to identify the
failing line and token on that line.

There has been a lot of discussions in the Bison and Flex lists about
adding error tracking features to that combination. Some like it, others
are even wholly opposed. One snag is to add something that is useful to the
totality of error tracking methods in use.

So I think that this is the current state of the matter.

It is good that you point out the problem with empty rules. A better might
be to keep track of the location of the current lookahead token, and the
position of that in the case an error occurs: LALR is different form LR in
that if an error is detected, it can do some more reductions, but it will
not shift any new tokens. So this lookahead token is "universal" with
respect to the error generated and these algorithms. By contrast, the Bison
default rule is not.

  Hans Aberg






reply via email to

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