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: Fri, 17 Nov 2006 17:07:46 -0500 (EST)

On Tue, 24 Oct 2006, Joel E. Denny wrote:

> 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

It occurs to me now that Bison wouldn't necessarily need to complain about 
conflicting value name declarations.  Bison could just complain about 
ambiguous value name uses.  That is, let's assume your proposal: omitting 
the `(name)' from `exp(name)' would request the default value name $exp.  
The following would be fine because it doesn't use $exp:

  exp : exp '+' exp { $$ = $1 + $3; }

Every $exp in the following would be ambiguous, and Bison would complain 
about each:

  exp: exp '+' exp { $exp = $exp + $exp; }

To use $exp at all, you'd need to override the default value name for at 
least two exp's:

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

On Tue, 24 Oct 2006, Paolo Bonzini wrote:

> <!> is really too hieroglyphic for
> me.  If anything, I would prefer <> or a trailing %untagged...

As a reminder, I've been proposing:

1. (name) = a value name, and <tag> = a type tag.

2. () = default value name.  Maybe <> = default type tag, but I know of no 
use for that right now.

3. (!) = no value name, <!> = no type tag, and both suppress some 
warnings.  In other words, `!' = void.

As much as I like the cautionary look of (!) and <!>, I now see a problem 
with the above scheme.  Bison may one day grow another kind of construct 
that would also need some sort of expression, default, and void forms. 
Let's say these are [expression], [], and [!], respectively.  While (name) 
and <tag> cannot contain a !, ! might prove to be a reasonable character 
in [expression] with some other expected meaning.  Since [!] would already 
have a meaning, void might have to be something like [-] instead.  
However, that would be inconsistent with (!) and <!>.  In the worst case, 
there would be no legible character to put in [expression] to mean void 
because all candidates have some other expected meaning.

Following your proposal instead, if () and <> would mean void, then it 
would be the empty string we'd have to worry about in [].  My guess is 
that the empty string is less likely to be a problem than ! is.  (This is 
not pure conjecture.  Although I'm not planning to use `[' and `]', I have 
something in mind, the ! bothers it, and the empty string does not.)

In summary, I'm now thinking the notation for value names and type tags 
would go like this:

  %destructor() {
    /* $$ is unused.  */
    printf ("A tagless symbol was discarded.\n");
  } <>

  %%

  grammar: defs rules epilogue() {
    /* epilogue somehow handled elsewhere.  */
    $grammar = new_grammar ($defs, $rules);
  }
  ;

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

Those ()'s look awfully innocent to be removing warnings, but I guess 
they're ok.

<*> would still mean any tag.

Opinions?




reply via email to

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