Named references allow one to use the name of the token (or nonterminal),
rather than its position in the production, to access its semantic value
or location.

   init : type IDENTIFIER '=' NUMBER ';'
          { declare_id($IDENTIFER, $type); set_value($IDENTIFIER, $NUMBER); }

But they fail to work when the token is a _literal character token_ or
a _literal string token_.

   init : type IDENTIFIER '=' NUMBER ';'
          { first_to_last($type, $';'); }

             /*** Error: this doesn't work

             Bison 3.0 gives the warning: stray '$' [-Wother]
             and leaves the $ untranslated, causing C compiler errors. */

Bison 3.0's named reference documentation shows that one can use them to
refer to tokens and nonterminals with fairly non-standard names (involving
dots and dashes), and even mid-rule actions without names.  But apparently
not literals, although named character literals have been around since the
creation of Yacc.

The only workaround I have found is to use the technique recommended
for giving explicit names to mid-rule actions, the postfix [name] trick:

   init : type IDENTIFIER '=' NUMBER ';'[SemiColon]
          { first_to_last($type, $SemiColon); }

This is pretty kludgy, to say the least.  Can this limitation be fixed?

- David Librik
lib...@panix.com

Reply via email to