Related articles |
---|
Parsing questions e8rasmus@etek.chalmers.se (Rasmus Anthin) (2000-01-06) |
Parsing Questions sewing@uvic.ca (Stefan Ewing) (2002-06-13) |
Re: Parsing Questions sting@linguist.dartmouth.edu (Michael J. Fromberger) (2002-06-14) |
Re: Parsing Questions ian@cfmu.eurocontrol.be (Ian Wild) (2002-06-14) |
Re: Parsing Questions joachim_d@gmx.de (Joachim Durchholz) (2002-06-14) |
Re: Parsing Questions rcbilson@plg2.math.uwaterloo.ca (Richard C Bilson) (2002-06-14) |
Re: Parsing Questions vbdis@aol.com (VBDis) (2002-06-14) |
Re: Parsing Questions sewing@uvic.ca (Stefan Ewing) (2002-06-17) |
Re: Parsing Questions sewing@uvic.ca (Stefan Ewing) (2002-06-17) |
From: | "Richard C Bilson" <rcbilson@plg2.math.uwaterloo.ca> |
Newsgroups: | comp.compilers |
Date: | 14 Jun 2002 15:21:43 -0400 |
Organization: | University of Waterloo |
References: | 02-06-034 |
Keywords: | C, parse |
Posted-Date: | 14 Jun 2002 15:21:43 EDT |
Stefan Ewing <sewing@uvic.ca> wrote:
>How can the postfix increment/decrement operators in C, C++, and Java
>be represented in a parse tree? For example, if we have the
>epxression
>
>a = b++ + c;
>
>b will be incremented after b + c has been calculated. But the only
>place to put the operator (it seems to me) is between "b" and "+".
>But doesn't this imply we should increment b *before* adding it to c?
You need to distinguish between the *value* of the expression "b++"
and its side effect (the increment). You can do the increment
anywhere you like (modulo a few restrictions), as long as the value
that is added to c is the original value of b. Your parse tree is
attempting to represent the steps required to compute the value of the
expression -- incrementing b doesn't play any part in determining this
value.
So I think your parse tree is probably right; I suspect that you'll
end up worrying about the side effect when you get to code generation.
For instance, you could move the value of b to a temporary, increment
b, and then add the temporary to the value of c.
- Richard
Return to the
comp.compilers page.
Search the
comp.compilers archives again.