Re: %token-table doesn't seem to be working for C++?

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.general
Message-ID <[email protected]>
Hi Derek,

Sorry for answering so late, I was on ⛷

> Le 2 mars 2019 à 21:13, Derek Clegg <[email protected]> a écrit :
> 
> On Feb 18, 2019, at 9:59 PM, Akim Demaille <[email protected]> wrote:
>> 
>> Let me answer with a question: what are you trying to achieve?
>> What do you need these for?
> 
> What I’d actually like to do is get the string name associated with a symbol.
> 
> For example, if I had
> 
> %token PLUS_ASSIGN     "+="
> %token MINUS_ASSIGN    "-="
> ...
> 
> then I could write something akin to
> 
> assignment-expression:
>  name assignment-op expression
>    { 
>      std::cout << "Assignment: " << get_name_of_op($2) << "\n";
>      $$ = build_assignment(get_name_of_op($2), $name, $expression);
>    }
> ;
> 
> assignment-op: "+=" | "-=" | ... ;

So we should provide a function that directly provides you with the
token name from its number.  I don't feel confortable when exhibiting
such low-level details.

However, if you don't want to wait for a release with this feature,
you can use these values:

    /// Constants.
    enum
    {
      yyeof_ = 0,
      yylast_ = 1,     ///< Last index in yytable_.
***   yynnts_ = 2,  ///< Number of nonterminal symbols.
      yyfinal_ = 3, ///< Termination state number.
      yyterror_ = 1,
      yyerrcode_ = 256,
***   yyntokens_ = 4  ///< Number of tokens.
    };


The documentation you are referring to is really the documentation
of the C skeleton.

Cheers!
_______________________________________________
[email protected] https://lists.gnu.org/mailman/listinfo/help-bison
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.