Re: Parsing Questions

"Richard C Bilson" <>
14 Jun 2002 15:21:43 -0400

          From comp.compilers

Related articles
Parsing questions (Rasmus Anthin) (2000-01-06)
Parsing Questions (Stefan Ewing) (2002-06-13)
Re: Parsing Questions (Michael J. Fromberger) (2002-06-14)
Re: Parsing Questions (Ian Wild) (2002-06-14)
Re: Parsing Questions (Joachim Durchholz) (2002-06-14)
Re: Parsing Questions (Richard C Bilson) (2002-06-14)
Re: Parsing Questions (VBDis) (2002-06-14)
Re: Parsing Questions (Stefan Ewing) (2002-06-17)
Re: Parsing Questions (Stefan Ewing) (2002-06-17)
| List of all articles for this month |

From: "Richard C Bilson" <>
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 <> 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
>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

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

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.