Wei
Not looking at the standard right now, but the following is valid:
x = 1, 2, 3; // x gets 3
A test for the second case would be
x = 3;
y = 3 * x = 2;
This should be an error, because 3 * x is not an lvalue.
Does this compile with tcc? (don't know, the machine I am on doesn't
have the compiler).
On Sat, 2009-09-05 at 01:05 +0800, Wei wrote:
Hi, TCC stackholders,
I am tracing TCC's source codes, and find something I don't understand.
What I don't understand is about the grammar.
From the C89 or C99 standard:
======================================================================
assignment_expression
: lvalue assignment_operator assignment_expression
| conditional_expression
;
======================================================================
However, in TCC,
======================================================================
static void gexpr(void)
{
while (1) {
expr_eq();
if (tok != ',')
break;
vpop();
next();
}
}
======================================================================
and expr_eq( ) seems to parse C conditional _expression_ (ie, xxx ? xxx : xxx).
It seems that it doesn't parse codes like "a = b = c = d = 4;".
And in the C standard,
======================================================================
multiplicative_expression
: (cast_expression) ('*' cast_expression | '/' cast_expression | '%' cast_expression)*
;
======================================================================
However, in TCC, the function to parse "multiplicative_expression" is expr_prod( ):
======================================================================
static void expr_prod(void)
{
int t;
uneq();
while (tok == '*' || tok == '/' || tok == '%') {
t = tok;
next();
uneq();
gen_op(t);
}
}
======================================================================
and uneq( ) seems to parse the so-call "assignment_expression.", not the standard-defined "cast_expression"
Why TCC uses such a grammar? it seems not compatible with the C standard.
Wei.
_______________________________________________
Tinycc-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/tinycc-devel