bison-patches
[Top][All Lists]
Advanced

[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 18:09:26 -0400 (EDT)

On Tue, 24 Oct 2006, Paolo Bonzini wrote:

> Joel E. Denny wrote:
> > On Tue, 24 Oct 2006, Paolo Bonzini wrote:
> > 
> > > What about <UNTAGGED>?  As in
> > 
> > An existing grammar might have a union field named UNTAGGED.
> 
> Can't deny that, but it seems unlikely...

May be, but with all the Yacc and Bison grammars out there, I wouldn't bet 
on it.

> <!> is really too hieroglyphic for
> me.

I realize <!> looks odd when considered in isolation, but I'm trying to be 
consistent with a couple of other proposals....

First, named semantic values:

  exp(sum): exp(term1) '+' exp(term2) {
    $sum = $term1 + $term2
  }
  ;

  grammar(): defs() rules() epilogue(!) {
    $grammar = new_grammar ($defs, $rules);
  }
  ;

Here, () = unspecified value name = default name = the symbol name.  That 
seems logical to me.  (!) = no value is used at all.  The ! conveys a 
sense of caution, which I think this is appropriate given that its purpose 
would be to disable any Bison warning about unused $3.

Second:

  %destructor(!) { printf ("A SYM was discarded.\n"); } SYM

Again, (!) = no value and conveys a sense of caution.  Again, it would 
disable Bison's warning about unused $$.

I don't want to create another notation for the same concept.  That is, 
while (!) would indicate no value, <!> would indicate no type tag.  
Avoiding Bison's static type system for some symbols often still warrants 
some caution, so that ! make sense to me.

All of this really comes together nicely when imagining a grammar in which 
you want to use <!> but you still have some other symbols with type tags.  
You would likely need to write:

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

> If anything, I would prefer <>

In my opinion, <> = unspecified tag = default tag, and I'm not sure what 
that is.  This interpretation is consistent with the () proposal.

> or a trailing %untagged...

%untagged seems reasonable in isolation.  However, I don't like the lack 
of symmetry with respect to <*> and (!).

I think any alternate proposal in this area should maintain the 
consistency of (), (value-name), <tag>, (!), <!>, and <*>.  (I don't know 
what <> or (*) would be, but maybe one day.)

What do you think?




reply via email to

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