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: | "Michael J. Fromberger" <sting@linguist.dartmouth.edu> |
Newsgroups: | comp.compilers |
Date: | 14 Jun 2002 13:58:50 -0400 |
Organization: | Dartmouth College, Hanover, NH, USA |
References: | 02-06-034 |
Keywords: | C, parse |
Posted-Date: | 14 Jun 2002 13:58:44 EDT |
"Stefan Ewing" <sewing@uvic.ca> writes:
>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?
Simply treat prefix and postfix versions as different unary operators
-- the parser can certainly be written to tell which it's got, and
generate an appropriate parse tree, e.g.:
=
/ \
a +
/ \
p++ c
|
b
Here, I mean for "p++" to mean "the postfix increment operator". How
you represent these in your compiler is, of course, up to you. :)
>Also, how should one represent the Java field access operator (.) in
>a parse tree? At first glance, it seems like a binary operator to me
>(given the object name and the field name, a memory address is
>returned), but one operator precedence chart I saw online shows . as
>a unary operator.
Where were you looking?
-M
--
Michael J. Fromberger Software Engineer, Thayer School of Engineering
sting <at> linguist.dartmouth.edu http://www.dartmouth.edu/~sting/
"If people do not believe that mathematics is simple, it is only because
they do not realize how complicated life is." -- John von Neumann
Return to the
comp.compilers page.
Search the
comp.compilers archives again.