Re: How to handle operator of undefined associativity

glen herrmannsfeldt <gah@ugcs.caltech.edu>
Wed, 5 May 2010 20:51:40 +0000 (UTC)

          From comp.compilers

Related articles
How to handle operator of undefined associativity singh.pallav@gmail.com (Pallav singh) (2010-04-29)
Re: How to handle operator of undefined associativity bear@sonic.net (Ray) (2010-05-01)
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: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.compilers
Date: Wed, 5 May 2010 20:51:40 +0000 (UTC)
Organization: California Institute of Technology, Pasadena
References: 10-04-073 10-05-011 10-05-020
Keywords: parse
Posted-Date: 09 May 2010 12:15:08 EDT

glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:
> BGB / cr88192 <cr88192@hotmail.com> wrote:
(snip)


>> but, with a unary operator, there is only a single possible parsing:
>> the operator and the expression it operates on.


> That is true if you allow only prefix operators, or only
> postfix operators, but not if you allow both. Consider C:


> *x++ is *(x++) or (*x)++


> Where * and ++ are both unary operators.


(snip)


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


So now I have to actually get out my K&R2...


I know that it always works as *(x++), but why?


It seems that * and ++ are at the same precedence level, but associate
right to left. I haven't actually looked at the table in many years,
yet haven't had much problem with precedence and associativity.
(There is, of course, the well known low precedence of << and >>.)


This could be avoided by not having postfix and prefix
operators at the same precedence level. It seems that
C didn't do that.


(I haven't looked at the C99 precedence table, but I will
presume that they didn't change this.)


-- glen
[I happen to have C99 here, and they did change it. The grammar separates out
postfix-expression and unary-expression, with postfix-expression coming first.
Offhand, I can't think of any plausible examples where the C99 grammar would
parse an expression differently. -John]



Post a followup to this message

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