[Nickle] sort of a bug

Keith Packard nickle@nickle.org
Fri, 14 Feb 2003 12:02:45 -0800


Around 19 o'clock on Feb 14, "Ireland Peddlar" wrote:

> Factorial is binding tighter than the preinrement operator.
> ++x! is parsed as ++(x!) and dies.

Hmm.  C has a single level of precedence for unary operators and groups 
them from right to left.  You'll get the same error from the C compiler 
with:

	int foo (int x) { return --x++; }

Because of the right to left binding, any postfix unary operators with the 
are effectively given higher precedence than prefix unary operators with 
the same specified precedence.

There's a problem here though; the grammar does operator precedence based
on the operator tokens in the input stream.  So, I can't change the 
precedence of the factorial operator without also changing the precedence 
of the boolean negation opertor as they share the same token.

I think that means we're stuck with this precedence inversion; I don't 
want to gratuitously differ from C in such a subtle way.

-keith