bug-bison
[Top][All Lists]
Advanced

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

Re: Bison C++ mid-rule value lost with variants


From: Frank Heckenbach
Subject: Re: Bison C++ mid-rule value lost with variants
Date: Sun, 08 Apr 2018 23:20:50 +0200

Hans Ã…berg wrote:

> > On 29 Jun 2017, at 15:55, Piotr Marcinczyk <address@hidden> wrote:
> > 
> > I supposedly found a bug in lalr1.cc skeleton with variant semantic type.
> 
> You might check if std::variant, of C++17, can be used instead. Cf.
>   http://en.cppreference.com/w/cpp/utility/variant
> 
> > When using mid-rule action { $<type>$ = value; } to return a value that
> > will be used in further semantic actions, it appears that the value on
> > stack becomes zero. Tested with Bison version 3.0.4.

This answer may come a bit late, but I had the same problem (and
others) recently, so I wrote a new Bison skeleton using std::variant
which, as Hans said, solves this problem.

You can find it here:

http://lists.gnu.org/archive/html/bug-bison/2018-04/msg00011.html

To use the new skeleton, change in parser.y:

-%skeleton "lalr1.cc"
+%skeleton "lalr1-c++17.cc"

Since tokens are now of std::variant type, compiling requires C++17,
e.g. gcc-7 with "--std=c++17" option, and tokens are built a bit
differently, so change in lexer.flex (or use make_int):

-                yylval->build(atoi(yytext));
+                yylval->emplace<int>(atoi(yytext));

Regards,
Frank



reply via email to

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