[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jdt-core-dev] extended operands in infix expressions - compiler AST output
|
Rory, From the API perspective, the spec for AST.parseCompilationUnit
does not specify the exact representation used for infix expressions. A
wise client should not depend it being one way or another, even though as
Olivier points out, the AST.parseCompilationUnit implementation does return
extended operands wherever possible. If you were constructing or editing an
infix expression AST by hand, you would have some flexibility.
Do you have a case where it would make a difference to clients if the spec
was more specific in this regard?
---Jeem
"Olivier Thomann"
<Olivier_Thomann@ot To: jdt-core-dev@xxxxxxxxxxx
i.com> cc:
Sent by: Subject: [jdt-core-dev] extended operands in infix expressions - compiler AST
jdt-core-dev-admin@ output
eclipse.org
09/18/2002 10:01 AM
Please respond to
jdt-core-dev
Question from Rory Lucyshyn-Wright:
I have a question regarding whether or not I can expect an AST returned by
the AST.parseCompilationUnit(...) methods to have certain properties.
Let T be an AST, representing a compilation unit, as returned by a
parseCompilationUnit(...).
Let the compilation unit's source code contain an expression E:
<Exp1> op <Exp2> op ... op <ExpN>
where the N is an integer greater than or equal to 2, op is a binary
operator, and the <Expi> are expressions at higher precedence than E.
Let S be the subtree of T representing E.
(note: I have included cases where E is <Exp1> op <Exp2>)
(note: The root of S will be an InfixExpression whose operator is op)
My question:
Is the following statement true?
No (direct) child of the root of S will be an InfixExpression whose
operator is op.
Discussion:
What I am asking is whether or not expressions like the following will
always be represented as one single InfixExpression whose extended operands
include all but the first 2 terms (or whether they will sometimes involve
more '+' InfixExpression nodes):
1 + 2 + 3 + 4 + 3
or
a*b + 2 + foo()
I am basically asking whether the InfixExpressions will always contain as
many nodes as possible in their extendedOperands lists.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Answer: The extentedOperands list is only used if ALL operators of an
expression are identical.
Therefore 1 + 2 + 3 + 4 + 3 will be represented by an infixexpression build
like this:
LeftOperand: NumberLiteral 1
RightOperand: NumberLiteral 2
extendedOperands: NumberLiteral 3, NumberLiteral 4, NumberLiteral 3
Operator: PLUS
Whereas a*b + 2 + foo() will be represented by an infixexpression build
like this:
LeftOperand:
InfixExpression
LeftOperand:
InfixExpression
LeftOperand: SimpleName a
RightOperand: SimpleName b
extendedOperands: empty
Operator: TIMES
RightOperand: NumberLiteral 2
extendedOperands: empty
Operator: PLUS
RightOperand: MethodInvocation foo()
extendedOperands: empty
Operator: PLUS
Hopefully this clarifies the infix expression.
Olivier
_______________________________________________
jdt-core-dev mailing list
jdt-core-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/jdt-core-dev