Re: how to get left hand side symbol in action

Derek Clegg <[email protected]>
Newsgroups gmane.comp.parsers.bison.general
Message-ID <[email protected]>

> On May 10, 2019, at 10:43 AM, Akim Demaille <[email protected]> wrote:
> 
> 
> 
>> Le 10 mai 2019 à 16:28, Christian Schoenebeck <[email protected]> a écrit :
>> 
>> On Freitag, 10. Mai 2019 06:57:00 CEST Derek Clegg wrote:
>>> In fact, I do not think error messages in the generated parser should be
>>> provided by bison, except as a trivial default. Instead, I’d like to see
>>> bison call a function (which I provide) when a syntax error occurs, with a
>>> list of what was expected along with what was encountered. Obviously, they
>>> should be provided without translation. That would be the most flexible.
>> 
>> Yep, I can just agree.
> 
> Except that you don't.  The API that was proposed initially did not
> fit your need.  At least, that was my understanding of
> 
> https://lists.gnu.org/archive/html/help-bison/2019-02/msg00018.html
> 
> Listen guys (Derek, Christian): how about you submit a patch of what
> you think the feature should be? 

I believe that my suggestion in the above post would be a good starting point. While Christian’s concern is valid, I think my proposal would be an improvement over the current method of error reporting. Just to reiterate, I suggested this approach:

> ...replace the code starting with
> 
>    char const* yyformat = YY_NULLPTR;
>    switch (yycount)
>      {
> #define YYCASE_(N, S)                        \
>        case N:                               \
>          yyformat = S;                       \
>        break
> …
> 	return yyres;
> 
> in yysyntax_error_ with a call like
> 
>    my_yysyntax_error(yyarg, yycount);
> 
> where “my_yysyntax_error” is a user-defined function which does the work of handling syntax error reporting.
> 
> In C++, we could be fancier: have two functions, one for a “pure” syntax error:
> 
>    void my_yysyntax_error();
> 
> and one for syntax errors involving unexpected tokens:
> 
>     void my_yysyntax_error(std::string unexpected_token, std::vector<std::string> expected_tokens);
> 
> The call would be something like this:
> 
>    if (yycount == 0) {
>      my_yysyntax_error();
>    } else {
>      my_yysyntax_error(yyarg[0], std::vector<std::string>{yyarg + 1, yyarg + yycount});
>    }


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