help-flex
[Top][All Lists]
Advanced

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

Re: why are locations dictated by bison?


From: Hans Aberg
Subject: Re: why are locations dictated by bison?
Date: Sun, 13 Jan 2002 14:28:27 +0100

At 16:57 -0800 2002/01/12, John W. Millaway wrote:
>Incidently, what does Bison do with that class anyway? What do you mean when
>you say that bison "propogates" locations? I tried defining my own
>YYLTYPE, but
>got compiler errors:

I think that the default definition of Bison's location class is originally
in the semantic ("hairy") parser, which Corbett, who originally wrote Bison
for use in his thesis work, somehow used. Then Akim (?) at some point added
the YYLTYPE default to bison.simple. (So you may not have one of the latest
Bison versions.)

The location value is an additional semantic value, with a special default
rule: If the semantic values can be reached in the rule action by $1, ...,
$n variables, then the location value can be reached by @1, ..., @n
variables. The location default (pseudo-code) rule is then
   @$.begin = @1.begin
   @$.end   = @n.end
where @@ is the value of the LHS.

The execution of this default rule takes time, which slows down the parser
down, as all semantic actions, but it does not alter the actual parsing.
(The current bison.simple skeleton file implements it by a separate stack,
but that is just a way to implement it: In one of my C++ versions, I use a
single state/semantic stack.)

All location data tracking clearly creates overhead, which one does in
order to convene the parser user in the case of an error.

One may also question if this default rule is correct: In the case of an
error, one probably just wants to indicate the location of the failing
token, which will be the last one of the rule. So in that case, the
location default rule might be
   @$.begin = @n.begin
   @$.end   = @n.end
(That is, if the failing rule variable is #k, one might use this value of
@k computed so far to display in the error message.) -- Just an input.

  Hans Aberg





reply via email to

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