Related articles |
---|
Writing a C Compiler: lvalues andre.nho@gmail.com (=?ISO-8859-1?Q?Andr=E9_Wagner?=) (2010-05-08) |
Re: Writing a C Compiler: lvalues ben.usenet@bsb.me.uk (Ben Bacarisse) (2010-05-09) |
Re: Writing a C Compiler: lvalues bartc@freeuk.com (bart.c) (2010-05-09) |
Re: Writing a C Compiler: lvalues tom@iahu.ca (Tom St Denis) (2010-05-09) |
Re: Writing a C Compiler: lvalues kst-u@mib.org (Keith Thompson) (2010-05-09) |
Re: Writing a C Compiler: lvalues esosman@ieee.org (Eric Sosman) (2010-05-09) |
Re: Writing a C Compiler: lvalues stargazer3p14@gmail.com (Stargazer) (2010-05-10) |
Re: Writing a C Compiler: lvalues marc@lithia.nl (Marc van Lieshout) (2010-05-16) |
Re: Writing a C Compiler: lvalues esosman@ieee.org (Eric Sosman) (2010-05-17) |
Re: Writing a C Compiler: lvalues kst-u@mib.org (Keith Thompson) (2010-05-17) |
Re: Writing a C Compiler: lvalues kst-u@mib.org (Keith Thompson) (2010-05-19) |
Re: Writing a C Compiler: lvalues bartc@freeuk.com (bart.c) (2010-05-19) |
Re: Writing a C Compiler: lvalues lawrence.jones@siemens.com (2010-05-19) |
Re: Writing a C Compiler: lvalues kst-u@mib.org (Keith Thompson) (2010-05-19) |
[3 later articles] |
From: | Marc van Lieshout <marc@lithia.nl> |
Newsgroups: | comp.lang.c,comp.compilers |
Date: | Sun, 16 May 2010 22:20:15 +0200 |
Organization: | Compilers Central |
References: | 10-05-036 |
Keywords: | C |
Posted-Date: | 16 May 2010 20:57:05 EDT |
On 08-05-10 15:34, Andri Wagner 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?
>
> 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
> lvalue?
An lvalue is an expression that evaluates to an address, so it *can* be
used on the left hand side of an assignment. But this is not necessarily
the case. In an expression like (x + 5) x *is* an lvalue, but it isn't
used as such, so it should be compiled as an ordinary rvalue. So in the
expression x = foo, x should be compiled as an lvalue (an address to
which a value is assigned), and in the expression foo = x, x should be
compiled to an rvalue (code that results in the value of x).
As far as I can tell, you're trying syntax-directed translation on a
C-like language. That can be done but, in a grammar like C, you have to
postpone compilation of an identifier until you know how it's used.
If you want to see an example of using immediate (syntax-directed)
compilation of a C-like language, look at the source code of David Betz'
BOB compiler. It compiles to bytecodes, which are interpreted by a
voirtual machine.
The original DrDobbs article:
http://www.drdobbs.com/184409401
The latest sources via:
http://www.xlisp.org/
Return to the
comp.compilers page.
Search the
comp.compilers archives again.