bison-patches
[Top][All Lists]
Advanced

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

Circular precedence


From: Valentin Tolmer
Subject: Circular precedence
Date: Thu, 01 Aug 2013 16:55:46 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7

In following the patch suggested about partial order precedence, I made a test case with a circular precedence, i. e. c > b > a > c As far as I know, such a precedence relationship was not only impossible to express directly with only precedence (%left etc...), but it was completely impossible, even using something like
e:
    e * e
|   f

f:
    f + f
|   NUM

(this represents * > +)

With the new system, it is entirely possible and gives an interesting result. As there is currently no check for circularity and (yet) no transitivity (although non-transitional relationships will always be possible), a naive resolution for this grammar
%token NUM

%gprec {
  %left a
  %left b
}

%gprec { %left c }

%precr a > c
%precr c > b

%%

e:
  e a e
| e b e
| e c e
| NUM

expresses these parses
1 a 2 a 3 ->  (1 a 2) a 3         //normal %left associativity
1 a 2 b 3 ->  1 a (2 b 3)         //b > a
1 a 2 c 3 ->  (1 a 2) c 3         // a > c
1 c 2 b 3 ->  (1 c 2) b 3         // c > b
1 b 2 a 3 ->  (1 b 2) a 3         // b > a

The question is, should this be possible? Is it needed? Is it a desirable behavior? For my part, I see no harm in keeping it, but maybe preventing users from creating more complicated cycles inadvertently would be better... (Maybe a warning with an %expect-cycle 1 like we have %expect-rr ?)

Tell me what you think!



reply via email to

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