Re: how to get left hand side symbol in action

Hans Åberg <[email protected]>
Newsgroups gmane.comp.parsers.bison.general
Message-ID <[email protected]>
> On 9 May 2019, at 08:50, Akim Demaille <[email protected]> wrote:
> 
>> Le 6 mai 2019 à 22:45, Hans Åberg <[email protected]> a écrit :
>> 
>>> On 6 May 2019, at 18:09, Akim Demaille <[email protected]> wrote:
>>> 
>>>> Le 6 mai 2019 à 14:50, Hans Åberg <[email protected]> a écrit :
>>>> 
>>>>> On 6 May 2019, at 11:28, r0ller <[email protected]> wrote:
>>>>> 
>>>>> Hi All,
>>>>> 
>>>>> Is it possible in *any* way to get the left hand side symbol in an action of a rule? Say, I have:
>>>>> 
>>>>> A : B C
>>>>> {<!-- -->
>>>>> std:cout<<"left hand side symbol is:"<<???
>>>>> };
>>>>> 
>>>>> I tried to find it out myself and googled a lot but didn't find anything:(
>>>> 
>>>> In the C++ parser, one can write:
>>>> std::cout << “LHS: " << yytname_[yylhs.type_get()] << std::endl;
>>> 
>>> But it's an internal detail, there is no guarantee it won't change.
>> 
>> Right, so it might be a feature request for the longer term.
> 
> I'm trying to see what would make sense.
> 
>> Perhaps a variation of $ and @ that gives access to the name,
> 
> I am very uncomfortable with this.  Symbol names are technical details,
> most of the time they are irrelevant to the end user, just like the
> the user of a piece of software does not care about the names of the
> functions: that's a implementation detail.
> 
> In addition, tokens have several names: the identifier, and the
> string name, like
> 
> %token <string> ID "identifier"
> 
> Not to mention that I also want to provide support for
> internationalization.  So what name should that be? ID?
> identifier? or identifiant in French?
> 
> Of course when you debug a grammar, the names of the symbols
> are very important, and that's why the debug traces need the
> symbol names.  Again, like when you debug a program: then
> function names matter.
> 
> In the present case, I believe that the names that r0ller want
> should really be part of *his* specification, they should
> not come from internal details such as the symbol name.  So
> I do think it is saner that the names are explicitly put in the
> action.
> 
>> or the raw stack value in case there are more stuff to access.
> 
> Which only exists in lalr1.cc.  And I think r0ller is using
> glr.cc.  Maybe once Valentin is done there will be symbols.

Perhaps it is best to see what he wants, which looks complicated, and perhaps provide something more stable. I can’t recall any other request for the grammar variable names.



_______________________________________________
[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.