|Writing a C Compiler: lvalues email@example.com (=?ISO-8859-1?Q?Andr=E9_Wagner?=) (2010-05-08)|
|Re: Writing a C Compiler: lvalues firstname.lastname@example.org (Ben Bacarisse) (2010-05-09)|
|Re: Writing a C Compiler: lvalues email@example.com (bart.c) (2010-05-09)|
|Re: Writing a C Compiler: lvalues firstname.lastname@example.org (Tom St Denis) (2010-05-09)|
|Re: Writing a C Compiler: lvalues email@example.com (Keith Thompson) (2010-05-09)|
|Re: Writing a C Compiler: lvalues firstname.lastname@example.org (Eric Sosman) (2010-05-09)|
|Re: Writing a C Compiler: lvalues email@example.com (Stargazer) (2010-05-10)|
|Re: Writing a C Compiler: lvalues firstname.lastname@example.org (Marc van Lieshout) (2010-05-16)|
|Re: Writing a C Compiler: lvalues email@example.com (Eric Sosman) (2010-05-17)|
|Re: Writing a C Compiler: lvalues firstname.lastname@example.org (Keith Thompson) (2010-05-17)|
|[7 later articles]|
|From:||Tom St Denis <email@example.com>|
|Date:||Sun, 9 May 2010 10:25:38 -0700 (PDT)|
|Posted-Date:||09 May 2010 16:07:08 EDT|
On May 8, 9:34 am, Andri Wagner <andre....@gmail.com> wrote:
> What I'm trying to say is: the compiler yields different assembly code
> for when 'x' is a lvalue and when 'x' is not a lvalue.
> This gets more confusing when I have expressions such as 'x++'. This
> is simple, since 'x' is obviously a lvalue in this case. In the case
> of the compiler, I can parse 'x' and see that the lookahead points to
> '++', so it's a lvalue.
> But what about '(x)++'? In this case, the compiler evaluates the
> subexpression '(x)', and this expression results the value of 'x', not
> the address. Now I have a '++' ahead, so how can I know the address of
> 'x' since all that I have is a value?
++ requires an object that an address can be taken of attached to
either the right or left which forms part of a larger expression.
so it's really
could be, for instance
(*(ptr + a))++
For all it matters.
I guess it depends on how you wrote your parser, but basically when
you encounter ++ it must either be before or after an expression whose
address is computable.
> All documentation that I found about lvalues were too vague, and
> directed to the programmer, and not to the compiler writer. Are there
> any specific rules for determining if the result of a expression is a
Read the BNF grammar for C. The full BNF form is in appendix A32 of K&R
C 2nd edition. Page 238 describes how to look at both post and prefix
BTW I don't claim to be a compiler theory expert so that's about all
the help you're gonna get from me :-)
Return to the
Search the comp.compilers archives again.