help-bison
[Top][All Lists]
Advanced

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

Re: How to change the default action for selected rules?


From: Akim Demaille
Subject: Re: How to change the default action for selected rules?
Date: Fri, 4 Oct 2013 13:59:27 +0200

Le 30 sept. 2013 à 11:01, Markus Elfring <address@hidden> a écrit :

> Hello,
> 
> I try to develop a small grammar. Unfortunately, I stumble on error messages
> like the following during the build process on my openSUSE system.

Hi!

> ...
> Building parser with bison 3.0
> parser.ypp:68.18-20: warning: type clash on default action: <char> != <> 
> [-Wother]
> value_character: '0'
>                  ^^^
> parser.ypp:69.21-23: warning: type clash on default action: <char> != <> 
> [-Wother]
>                   | '1'
>                     ^^^

The warning is telling you that value_character is typed, expecting
$$ to have a value, but '0' and '1' have no value associated.  You
should provide them with a value.

> ...
> 
> 
> I guess that this happens because of this setting for better C++ support.
> %define api.value.type variant
> http://www.gnu.org/software/bison/manual/bison.html#C_002b_002b-Variants

No, this is unrelated.

> I have found the following comment in a source file.
> http://git.savannah.gnu.org/cgit/bison.git/tree/data/lalr1.cc?id=cc8962bdde81b04aa728aef21e53b4a08a0debfe#n818
>    /* Variants are always initialized to an empty instance of the
>       correct type. The default $$=$1 action is NOT applied when using
>       variants.  */

> Now I am interested in further solutions.
> - Can the used variant template class be extended?

You are not expected to extent it, just used it.  See the
corresponding section.

> - Is a conversion possible without the specification of a specific data type 
> in
> a directive like "%token"?

I'm not sure to understand what you mean.  If '0' is expected
to have a value, then you should declare it

%token <character> '0' '1'

> - The character list can become long in my use case here.

That's weird.  Maybe should have a single token type 'character',
and store the character value in its semantic value.

> I would like to avoid
> the repetition of similar actions behind them. It would be more "convenient" 
> to
> choose a different default action for selected rules, wouldn't it?


One usually does not need that, as this kind of job is typically
left to the scanner/lexer, not to the parser.




reply via email to

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