help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Akim Demaille
Subject: Re: %token-table doesn't seem to be working for C++?
Date: Thu, 14 Mar 2019 07:07:59 +0100

Hi Derek,

Sorry for answering so late, I was on ⛷

> Le 2 mars 2019 à 21:13, Derek Clegg <address@hidden> a écrit :
> 
> On Feb 18, 2019, at 9:59 PM, Akim Demaille <address@hidden> 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!


reply via email to

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