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: Thu, 1 May 2003 10:57:47 +0200

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.

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'

  %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.

- 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:
...
  if (len_)
    {
      Slice< LocationType, LocationStack > slice (location_stack_, len_);
      YYLLOC_DEFAULT (yyloc, slice, len_);
    }

  #ifdef YYPRE_ACTION
    YYPRE_ACTION YYPRE_ACTION(len_)

  switch (n_)
    {
      b4_actions
    }
...

Then you have to define
  #define YYPRE_ACTION(rule_length) ...

  Hans Aberg






reply via email to

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