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

2019-03-02 Thread Derek Clegg
On Feb 18, 2019, at 9:59 PM, Akim Demaille  wrote:
> 
> Hi Derek,
> 
>> Le 18 févr. 2019 à 21:07, Derek Clegg  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


___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

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

2019-03-02 Thread John P. Hartmann
Alas, the scanner is allowed to return an integer only.  It cannot 
return a string.


Anyhow, your sample %token statement declares two tokens, not one; the 
last being meaningless.


On 3/2/19 21:13, Derek Clegg wrote:

On Feb 18, 2019, at 9:59 PM, Akim Demaille  wrote:


Hi Derek,


Le 18 févr. 2019 à 21:07, Derek Clegg  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


___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison



___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

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

2019-03-02 Thread Derek Clegg
Thanks for your response. I suggest you read through the bison manual, 
particularly the section on token type names, in order to better understand my 
question.

Derek

> On Mar 2, 2019, at 12:26 PM, John P. Hartmann  wrote:
> 
> Alas, the scanner is allowed to return an integer only.  It cannot return a 
> string.
> 
> Anyhow, your sample %token statement declares two tokens, not one; the last 
> being meaningless.
> 
> On 3/2/19 21:13, Derek Clegg wrote:
>> On Feb 18, 2019, at 9:59 PM, Akim Demaille  wrote:
>>> 
>>> Hi Derek,
>>> 
 Le 18 févr. 2019 à 21:07, Derek Clegg  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
>> ___
>> help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison
> 
> ___
> help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison


___
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison