[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Named references do not work with literal tokens in Bison 3.0
From: |
David Librik |
Subject: |
Named references do not work with literal tokens in Bison 3.0 |
Date: |
Sun, 29 Jun 2014 05:30:26 -0400 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
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
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Named references do not work with literal tokens in Bison 3.0,
David Librik <=