[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: FYI: default %printer/%destructor
From: |
Joel E. Denny |
Subject: |
Re: FYI: default %printer/%destructor |
Date: |
Tue, 24 Oct 2006 21:52:24 -0400 (EDT) |
On Wed, 25 Oct 2006, Paolo Bonzini wrote:
> > grammar(): defs() rules() epilogue(!) {
> > $grammar = new_grammar ($defs, $rules);
> > }
> > ;
> Here you won't break grammar source compatibility by omitting the ()
> altogether.
If Bison were to complain about value name conflicts (and I think it
should), you would have trouble with:
exp: exp '+' exp
> > %destructor(!) { printf ("A symbol was discarded.\n"); } <!>
> >
> > Here, symbols with no type tags have no values but still have a %destructor.
> >
> > Of course, if no symbols in your grammar have type tags, or if you plan to
> > use $<tag>$ extensively for untagged symbols, it might be reasonable to have
> > <!> without (!) in a %destructor.
> >
> I still don't see much similarity with (!)
<!> = no tag. (!) = no value. Both cases warrant caution. Those are the
similarities. Maybe I don't understand what you're saying.
> and Then, why not having
>
> %destructor BLOCK
>
> implement a <*> destruction, and something like
At one time I implemented the empty symbol list notation to indicate a
default destructor. Akim and I agreed that was ugly. To me, it reads
like a syntactic mistake. Moreover, one might want the <*> and <!>
destructor to be the same, and it's nice not to have to repeat code:
%destructor(!) { printf ("A symbol was discarded.\n"); } <!> <*>
> %destructor(!) BLOCK
> %destructor BLOCK %pragma(unused-value)
>
> implement a <!> destruction? Going for the latter, of course, would imply the
> possibility to do
>
> %destructor BLOCK %pragma(unused-value) <foo>
>
> even if foo is not untagged.
It doesn't make sense to me that (!) should mean "no value" in rules but
"no type tag" in %destructor. Maybe I don't understand what you're
saying.
> For now, this would mean having only the semantics of <*> available.
I'm a bit lost. I thought you just proposed an empty symbol list with (!)
as a replacement for <!>. Did I misunderstand?
> But besides debugging code, why would <!> functionality be useful?
You might use @$ in the %destructor to report the locations of discarded
symbols to the user.
More importantly, if you don't use a union, you might do something like
this:
#define YYSTYPE struct node*
%destructor { node_free ($$); } <!>