Joel - > I prefer that the clean-up *not* happen automatically for either YYABORT > or YYERROR -- as in GLR parsing. This would allow for a simple consistent > rule: if the user's semantic action executes, then the user's semantic > action is responsible for cleaning up RHS semantic values... regardless of > how the user's semantic action terminates.
the reason I prefer the automatic cleanup is that I generally like 'atomic' behavior of functions (actions in this case). Atomic = either the function/action _completely_ succeeds, or _completely_ fails. If it fails, the resulting state should be as if the function was never called. If you move the responsibility of cleanup when doing YYERROR/YYABORT into the action, you break this atomic design: If the action fails, it must now return in a different state than when it was called, otherwise the right-hand semantic values will be leaked (never cleaned up by anyone). On top of this design issue there is a practical advantage: There must be a built-in cleanup anyway, so the manual cleanup of RHS values is redundant, only increases code size for no good reason. Regards, Wolfgang On Monday 17 October 2005 08:34, Joel E. Denny wrote: > On Sun, 16 Oct 2005, Wolfgang Spraul wrote: > > Let's say you have an action that gets an object passed in which has a > > destructor. When using YYABORT inside the action, the destructor for this > > object is always called. When using YYERROR, it is never called, i.e. the > > action needs to destruct passed objects itself before using YYERROR. > > It seems like this behavior ought to be consistent between YYERROR and > YYABORT. > > Another inconsistency is that, while your above description is accurate > for yacc.c, it is not accurate for glr.c. That is, a GLR parser doesn't > call destructors in either case. > > > One could lean either way on the question whether YYABORT/YYERROR should > > or should not destruct objects passed to actions. At least with 2.1 the > > behavior is clean, and I'm fine (I'm mostly using YYABORT now and prefer > > the built-in cleanup). > > I prefer that the clean-up *not* happen automatically for either YYABORT > or YYERROR -- as in GLR parsing. This would allow for a simple consistent > rule: if the user's semantic action executes, then the user's semantic > action is responsible for cleaning up RHS semantic values... regardless of > how the user's semantic action terminates. > > I've also noticed that the bison documentation says: > > Note that in the future, Bison might also consider that right hand > side members that are not mentioned in the action can be destroyed. > > If this is implemented, I believe that it should be implemented > consistently for all three cases: the user's semantic action completes > successfully, it calls YYABORT, or it calls YYERROR. > > What does everyone else think? > > Joel _______________________________________________ Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison