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: Thu, 23 Nov 2006 19:42:29 -0500 (EST)

On Thu, 23 Nov 2006, Paul Eggert wrote:

> "Joel E. Denny" <address@hidden> writes:
> 
> > Sorry, I have no experience with ML.  Would you should me how this might 
> > look in a Bison rule?
> 
> Not offhand.  C isn't ML, and we'd have to construct types or
> something like that.  It'd take some thinking.  But the basic idea is
> that the EBNF X* has type "list of whatever X returns", and X? maps to
> "either an X-type value, or a null pointer".

And what if X is an alternation of symbols with different types?

Well, this reminds me of the proposal I made for treating the error token 
as a nonterminal.  (I posted it to Bison patches on Aug. 21, but the 
archives are down, so I can't get the URL right now.)  I suppose it would 
be possible for the user to designate a special ebnf symbol and type and 
then provide generic rules similar to the rules I was proposing for the 
error token:

  %ebnf-sym ebnf;
  %type <list> ebnf;
  ebnf:
    /* empty */     { /* Init $$.  */                                   }
    | ebnf sym1     { /* Append sym1 to $$.  */                         }
    | ebnf SYM2     { /* Append SYM2 to $$.  */                         }
    | ebnf <field1> { /* Automatic rules for syms of type <field1>.  */ }
    | ebnf <field2> { /* Automatic rules for syms of type <field2>.  */ }
    | ebnf <list>   { /* Automatic rules for syms of type <list>.  */   }
    | ebnf <*>      { /* Default rule for tagged symbol?  */            }
    | ebnf <>       { /* Default rule for tagless symbol?  */           }
    ;

Bison would not allow rules of any other form when the LHS is the ebnf 
symbol.

Now, borrowing a part of Akim's example, the alternations and repetitions 
below would be constructed using the generic rules above:

  options: (opt1 | opt2) (',' (opt1 | opt2))*

There are two groups on the RHS of this rule.  In this rule's semantic 
action, each group would have the type of the ebnf symbol, <list>.  The 
values are $1 and $2, but if you want to name the values:

  options: (opt1 | opt2)[a] (',' (opt1 | opt2))*[b]

Now, $a and $b will work.

Ok, I guess I'm on board with EBNF... as a very distant prospect.  
However, I still wonder if ISO EBNF is the right language.  Aren't most 
Lex and Yacc users more familiar with notations like "(...)*", "(...)?", 
and "(...)+"?

> I think "/" bugs me because it means "or" in ABNF, which is the
> standard grammatical notation used in Internet RFCs; see
> <http://www.ietf.org/rfc/rfc4234>.

That's fine.

> > I don't much like the `-' to mean nothing.  I had originally suggested `!' 
> > instead, but I found a reason why I don't like it either, and that reason 
> > also applies to `-'.  This one post might help you catch up:
> >
> >   http://lists.gnu.org/archive/html/bison-patches/2006-11/msg00039.html
> 
> Sorry, I don't follow the argument there.  How does it apply to "/"
> (or "#" or whatever)?

The argument there isn't about the choice of "/" or "#" or "()" or "[]".  
It's about the choice of "!" (or "-" in the current discussion) to mean 
nothing.  I prefer the empty string to mean nothing.




reply via email to

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