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: Derek Clegg
Subject: Re: %token-table doesn't seem to be working for C++?
Date: Sat, 2 Mar 2019 12:13:50 -0800

On Feb 18, 2019, at 9:59 PM, Akim Demaille <address@hidden> wrote:
> 
> Hi Derek,
> 
>> Le 18 févr. 2019 à 21:07, Derek Clegg <address@hidden> a écrit :
>> 
>> Perhaps I’m doing something wrong, but it appears that, in C++, %token-table 
>> doesn’t work: instead of yytname, I only see yytname_. It also appears that 
>> YYNTOKENS, YYNNTS, YYNRULES, and YYNSTATES are not defined, contrary to the 
>> documentation. Am I missing something, or is this broken?
> 
> 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: "+=" | "-=" | ... ;

Derek




reply via email to

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