help-bison
[Top][All Lists]
Advanced

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

Re: Finding out when a token is consumed


From: Hans Aberg
Subject: Re: Finding out when a token is consumed
Date: Sun, 11 May 2003 12:16:06 +0200

At 01:06 +0200 2003/05/11, Frank Heckenbach wrote:
>> I can't come up with any better suggestions than what has already been
>> said, given the limited context background. You might wait to see if
>> somebody else wakes up and giver further inputs.
>
>OK. It seems most likely by now that there isn't any better solution
>than the location abuse. At least, this is a very localized change,
>so it will be easy to replace it in the future, if I get to know
>about a better method ...

If that works, that seems to be one of the simplest method. It would be
easy for you to make your own skeleton file with its own macro right before
the action switch statement; then a supply that file also in a
distribution. Then you can turn off the location feature.

In this variation, what you ask for is essentially a statement
    %preaction <code>
with <code executed right before any other action. It would probably not be
very difficult to supply Bison with such a feature, if somebody is willing
to supply it. (Essentially what is needed is putting <code> in a M4 macro,
and then insert that macro in the skeleton files right before the action
switch statement.)

Next, you can have a look at the %print feature. I think it does nothing
but giving the chance to insert an extra action. This could be for
printing, but I do not think it must be.

It would be nice with a feature that tells whether the lookahead is needed
or not, so one can implement sure context switches. While at tweaking the
skeleton files, there is a segment:

yybackup:

  // Try to make a decision without lookahead:
  n_ = pact_[state_];
  if (n_ == pact_ninf_)
    goto yydefault;

  // Read a lookahead token.
  if (lookahead_ == empty_) {
    YYCDEBUG << "Reading a token: ";
    lex_();
  }

Here you can clearly determine whether a lookahead is used or not. So if
you can find a good tweak for your purposes, it might be interesting for
you to report to Bug Bison how you did it so that it can be used as a
feature in Bison:

I think it would be of general interest to get a better handling of this
lookahead problem.

  Hans Aberg






reply via email to

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