[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bison location tracking ..
From: |
Vardhan Varma |
Subject: |
Re: bison location tracking .. |
Date: |
Wed, 9 Jun 2004 11:29:37 -0700 (PDT) |
--- Hans Aberg <address@hidden> wrote:
> >> I've defined yylocation type to struct { offset,
> size
> >> }, and all that's working great.
> >>
> >> my problem is blank RHS .. offset gets set to
> zero.
> >> so in rule like
> >> atoms: /* blank */
> >> | atoms ATOM
> >> since first blank rule gets fired, the offset &
> size
> >> are set to zero.
> >>
> >> Do you have any workaround/solution for this
>
Well, I figured out this function does the right thing
for me:
typedef struct YYLTYPE
{
int start;
int finish;
} YYLTYPE;
# define YYLLOC_DEFAULT(Current, Rhs, N)
updyylval(&Current, Rhs, N);
void updyylval(YYLTYPE *Current, YYLTYPE Rhs[], int
N) {
int i;
Current->start = Current->finish = -1;
for ( i = 1 ; i <= N ; i ++ )
if ( Rhs[i].start != -1 ) {
Current->start = Rhs[i].start;
break;
}
for ( i = N ; i >= 1 ; i -- )
if ( Rhs[i].finish != -1 ) {
Current->finish = Rhs[i].finish;
break;
}
//dump(Current);
}
> The Bison location tracking feature is currently
> left essentially
> unsupported, in part because no-one seems to agree
Well, It's unsupported, but thankfully not broken.
> on what a suitable
> location tracking ought to be. The Bison default
> location tracking rule
> attempts to pinpoint the total area of the current
> grammar symbol. So, for
> the empty symbol, there is no location yet.
I'm newbie, but somehow my func above seems to be
working for empty RHS also. ( make them -1/-1 , since
N is zero ).
>
> A more prudent location tracking method for use with
> error reporting seems
> to be to keep track of the location of the current
> lookahead token, i.e.,
> its line number and its location on the line. Then
> that must be implemented
> explicitly. Perhaps a tweak of the skeleton file
> might help.
>
> Hans Aberg
The perfect way of doing thins is certainly welcome,
but lesser-learned of the tribes must use what's
availble today.
--Regards
--Vardhan
>
>
=====
--
Vardhan
__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/