[Nickle] bug
Keith Packard
nickle@nickle.org
Fri, 07 Feb 2003 17:49:19 -0800
Around 1 o'clock on Feb 8, "Ireland Peddlar" wrote:
> Yet another nickle bug!
> int x = 0;
> x == 0 ? x = 1 : x = 2 is evaluated as (x == 0 ? x) = (1 : x = 2)
> so it must be typed as x == 0 ? (x = 1) : (x = 2).
Would you believe the grammar was factored to avoid a shift/reduce conflict
in array/struct initializers?
Consider the two initializers:
typedef struct { int y; } Y;
Y x = { y = 7 };
int y;
int[1] z = { y = 7 };
The second initializer is syntactically indistinguishable from the first.
The current grammar avoids this ambiguity by making assignments invalid in
initializers -- they're factored out by creating an intermediate
non-terminal for assignment expressions above the rest of the expression
productions and having initializers use the lower level non-terminal.
I just reworked the grammar to move assignment back into the lower level
non-terminal. This yields an additional shift/reduce conflict, but shift
yields a struct initializer while reduce yields an array initializer, which
is what you want. If you want an array initializer to be an assignment
expression, just place it in parens.
Make sure you do 'make clean' after checking this change out; the makefile
doesn't rebuild the right things after the grammar changes. Bart should
fix this.
-keith