I guess it might be helpful, I can not claim yet : )
there is %initial-action declaration and the %final-action may help,
but rhs symbols will not be discarded.

%initial-action
{
try {
}

%final-action
{
   }
   catch (std::exception &)
   {
      yyerror(...);
      YYABORT;
   }
}

into some semantic action
{
    $$ = new SomeType;   // no exception
    $$->push_back(*$1);   // no exception
    $$->push_back(*$2);   // throws bad_alloc, $1, $2 leaks
}

and I have no idea how to work with M4: (


2011/5/26 Hans Aberg <[email protected]>

> On 24 May 2011, at 20:32, Sergey Klimkin wrote:
>
> > Trying to find information about C++ exceptions in semantic actions, with
> no
> > results.
> > Is there any Bison %Decl which allows to move parse stack outside
> yyparse(),
> > to destroy a stack values after an exception was thrown within semantic
> > action!?
>
> The C++ parser, I recall, is by default pure. So it would not be possible
> to save the stack outside yyparse() unless tweaking the skeleton file. But
> that should be kept to a minium in order to having to update it with new
> Bison releases - it may change.
>
> So you might try the construct
>  %code qualifier {code}
> (see the Bison manual sec. 3.7.14). I think that qualifier just expands a
> M4 macro to {code}. So you might put a try-catch inside yyparse(), and use
> %code to place the catch code.
>
> Hans
>
>
>
_______________________________________________
[email protected] https://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to