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: Frank Heckenbach
Subject: Re: Finding out when a token is consumed
Date: Thu, 1 May 2003 14:20:24 +0200

Hans Aberg wrote:

> At 01:18 +0200 2003/05/01, Frank Heckenbach wrote:
> >> > This is still too unspecific. Do you have an example?
> >>
> >> actually I would like to see his example too, as it sounds like something I
> >> wanted to do while debugging so I could "follow" what my grammar was going
> >> as it sucked input.
> >
> >Sorry, but I gave an example in my original posting. Whether it just
> >writes `consumed token ...' or does something more complicated with
> >the token is really irrelevant as far as bison in concerned. I
> >haven't written the other code yet, so I can't show it.
> 
> We try to guess what you want.

Sorry if my descriptions are so unclear. Basically, I'd like to do
what I did in my original example, but preferably without (ab)using
YYLLOC_DEFAULT, that's all.

> If you want to attach a code snippet to each action without having to write
> it out explicitly into each action, here are some suggestions:
>
> - The Bison file tests/actions.at has some code
>   %printer { fprintf (yyout, "%d from %d", $$, @$.first_line); }
>     input line thing 'x'

%printer doesn't seem to be documented yet, but from what I've found
(http://mail.gnu.org/archive/html/bison-patches/2002-06/msg00066.html,
e.g.), it seems to be like YYPRINT (though token-specific). So it
seems to be more for debugging and messages than for what I need.

>   %destructor ...
> which I think might do the trick. I found no explanation of it in the Bison
> manual, so perhaps this stuff is still experimental. -- Perhaps Akim
> Demaille can explain.

It is documented (at least in the CVS version). But AFAIUI, it is
only run for tokens that are discarded, not for those that are used
in the actions (which is the normal case in my grammar, of course).

> - You could use YYLLOC_DEFAULT as you do, or tweak the Bison skeleton file
> to insert you new favorite macro: All this macro does is to be executed
> right before the "switch" statement that selects the other rule actions.
> 
> If you tweak the Bison skeleton file (say lalr1.c), it might look like:
> ...
> [...]

I think this should work. The disadvantage is that I have to modify
the Bison output after it's generated (I guess this can be automated
with sed).

So it seems I'll have to decide between this and abusing
YYLLOC_DEFAULT. Thanks for the help.

Frank

-- 
Frank Heckenbach, address@hidden
http://fjf.gnu.de/
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)




reply via email to

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