On 22 Nov 2006, at 19:41, vlad florentino wrote:

In gnu bison:

I have a couple of productions of this type:
ID '.' complex
 : {...}
 ;

complex
 : FOOBAR  {...}
 ;

How can I pass the value of ID, a terminal, down to the production
'complex', a non terminal. I would like to determine what's the value of ID
and take actions based on that, i.e.:
 complex
 : FOOBAR
 {
   if( strcmp(ID.value,"this") == 0)
     doThis();
   else
     doThat();
  }

You can't within the parser itself, as it is a bottom-up parser; so some trick is needed. So either use variable global to the parser, or write it in the action of the first rule you have above (using $1). You might also attempt using negative $k numbers (perhaps $-1 in your case), but that is tricky: for one, thing, it will break if you variable "complex" is used in some other context.

  Hans Aberg




_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to