Re: How to handle operator of undefined associativity

Chris F Clark <cfc@shell01.TheWorld.com>
Thu, 06 May 2010 16:36:34 -0400

          From comp.compilers

Related articles
[2 earlier articles]
Re: How to handle operator of undefined associativity bartc@freeuk.com (bart.c) (2010-05-01)
Re: How to handle operator of undefined associativity cr88192@hotmail.com (BGB / cr88192) (2010-05-01)
Re: How to handle operator of undefined associativity cfc@shell01.TheWorld.com (Chris F Clark) (2010-05-02)
Re: How to handle operator of undefined associativity gah@ugcs.caltech.edu (glen herrmannsfeldt) (2010-05-03)
Re: How to handle operator of undefined associativity cr88192@hotmail.com (BGB / cr88192) (2010-05-05)
Re: How to handle operator of undefined associativity gah@ugcs.caltech.edu (glen herrmannsfeldt) (2010-05-05)
Re: How to handle operator of undefined associativity cfc@shell01.TheWorld.com (Chris F Clark) (2010-05-06)
Re: How to handle operator of undefined associativity sh006d3592@blueyonder.co.uk (Stephen Horne) (2010-05-07)
Re: How to handle operator of undefined associativity pat@jantar.org (Patryk Zadarnowski) (2010-05-10)
Re: How to handle operator of undefined associativity alex.colvin@valley.net (mac) (2010-05-12)
Re: How to handle operator of undefined associativity gah@ugcs.caltech.edu (glen herrmannsfeldt) (2010-05-12)
| List of all articles for this month |
From: Chris F Clark <cfc@shell01.TheWorld.com>
Newsgroups: comp.compilers
Date: Thu, 06 May 2010 16:36:34 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 10-04-073 10-05-011 10-05-020
Keywords: parse, design
Posted-Date: 09 May 2010 12:17:31 EDT

Ok, I can't help myself from chiming in one more time.


> [This isn't associativity, it's precedence. Humph. -John]


As our moderator says most uses of the word associativity in this
thread for unary operators are actually instances of precedence.


The one place where associativity might come into play is a place
where we had both prefix and suffix unary operators as the same
precedence [level].


It would look something like the following grammar:


      left "!" "*"; // we have 2 operators at the same precedence and
      they are left "associative".


      expr: "!" expr | expr "*"; // ! is prefix and * is suffix.


I believe this will associate the operators like this (if not then I
have described right associativity (and reverse it for left or vice
versa)):


    !!x** => ((!(!x))*)*


Note that the same effect can be achieved by simply having the !
operator be higher precedence than *. Now, if we also have versions
of the operators that were unary of the other form.


      expr: "*" expr | expr "!"; // ! is suffix and * is prefix.


You could write expressions of this form:


    *!x!* => ((*(!x))!)*


Now, having an operator be both unary prefix and suffix will give you
plenty of other issues, but it *could* be done. In that case the
associativity of unary operators makes sense, and it is distinct from
precedence. See how ! is not higher precedence than * or vice versa.
You might say that the prefix versions of the operators are higher
precedence than the suffix version, which is what associativity means
for unary operators. (Or at least that's the only sense I can make of
the word.)


Hope this helps,
-Chris


******************************************************************************
Chris Clark email: christopher.f.clark@compiler-resources.com
Compiler Resources, Inc. Web Site: http://world.std.com/~compres
23 Bailey Rd voice: (508) 435-5016
Berlin, MA 01503 USA twitter: @intel_chris
------------------------------------------------------------------------------



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.