bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Controlling the effects of precedence declarations


From: Frank Heckenbach
Subject: Re: Controlling the effects of precedence declarations
Date: Wed, 14 May 2003 05:04:44 +0200

Hans Aberg wrote:

> >> If you can give an exmple, that would help.
> >
> >To use a canonical example, suppose you have a typical grammar for
> >arithmetic expressions using precedence (see attachment). Later you
> >decide to add the unary minus, so you add a rule:
> >
> >  expr: '-' expr { $$ = -$2; };
> >
> >Bison just accepts this and assigns the rule the same precedence as
> >the binary minus. This may or may not be what you intended. In some
> >languages, unary minus has in fact this precedence (like in
> >mathematics), in other languages (e.g., C) it has a higher
> >precedence. But bison does not even tell you that there is a
> >conflict which is resolved this way (unless you check the verbose
> >logs).
> 
> This is an example;

Well, you asked for one. ;-)

> one should use %prec here.

Exactly. That's why I want Bison to tell me that there's a conflict
at all (which I otherwise might have overlooked if I didn't know the
problem already).

> You are slipping into the general discussion: "How can a language be
> designed so that only sensible programs can be written".

I never claimed this. Of course, that's impossible in general. I
just want to protect against one specific form of subtle problems.

> You might try to use %prec everywhere,

Quite the contrary of what I want ...

> The names declared in the precedence declaration are not tokens, but only
> use in the rules via %prec statements.

Yes, that's what I do (for the rules; for the look-ahead tokens,
it's not possible).

> >What I like is do to without such restrictions as far as possible
> >and only use precedence when I really think I need it, i.e. to let
> >bison do as *little* as possible in the area of precedence.
> 
> Then the set of precedence restrictions is empty in the case you do not
> need it.

As I said, I need it in a few cases. But I don't want the set to
become bigger by "accidental" precedence relations.

> >> But nobody is working with it for now.
> >
> >I think the second of my suggestions (no default precedence for
> >rules) is probably rather easy to implement. If I do so, will it be
> >accepted, or are there "philosophical" reservations against it? (I'm
> >asking because my time is quite limited, and if it would be rejected
> >anyway, I don't need to waste my time with it.)
> 
> I think the most philosophical restriction against featuritis in this group
> is to find somebody willing to implement it. :-)

OK. Here's a patch against 20030320, hope that's alright.

Frank

-- 
Frank Heckenbach, address@hidden
http://fjf.gnu.de/
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)

Attachment: bison-20030320.diff-no-default-precedence
Description: Binary data


reply via email to

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