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
------------------------------------------------------------------------------
Return to the
comp.compilers page.
Search the
comp.compilers archives again.