help-bison
[Top][All Lists]
Advanced

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

Re: Is there an option to change the message produced by YYERROR_VERBOSE


From: Simon Sobisch
Subject: Re: Is there an option to change the message produced by YYERROR_VERBOSE?
Date: Wed, 27 Apr 2016 22:51:36 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2

Hi Matthias.

> Hi Simon,
> 
> depending on your grammar, you might treat the keyword as an identifier and 
> just throw a warning in the lexer:
> 
> 
> 
>         "banana" {
>                 if (!SUPPORTS_KEYWORD(yyextra->config.std)) {
> 
> fprintf(stderr, "warning: `banana' keyword not available\n");
> 
>                         return TOK_ID;
>                 }
>                 return TOK_KW_BANANA;
>         }

This won't work as depending on the -std you may either use "banana" as
keyword or as identifier - and you won't want a warning for the second one.

> 
> Alternatively, semantic predicates might help you:
> 
> http://www.gnu.org/software/bison/manual/bison.html#Semantic-Predicates

This looks very nice, although it would main to always use the words as
keywords, wich won't help for the "this is an identifier, not a
keyword"-issue.
But Semantic Predicates are nice (did not know about Bison supporting
this before), so it likely help with other issues ;-)

> 
> 
> 
> Or the lexer could store the last few keywords in a global list and --instead 
> of parsing `unexpected %s'-- yyerror uses this list.
> But I am not sure about that one, I would expect its success depends
heavily on the parser-algorithm.

Seems a little bit like the suggestion from Hans, I'll have a look at
this later.

> 
> 
> Cheers,
> Matthias
> 
> 



reply via email to

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