tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] A TCC C parser question about the grammar


From: Wei
Subject: [Tinycc-devel] A TCC C parser question about the grammar
Date: Sat, 5 Sep 2009 01:05:15 +0800

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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]