help-bison
[Top][All Lists]
Advanced

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

Re: bison and C++ exceptions


From: Sergey Klimkin
Subject: Re: bison and C++ exceptions
Date: Thu, 26 May 2011 09:35:18 +0400

 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 <address@hidden>

> 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
>
>
>


reply via email to

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