[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[jdt-core-dev] extended operands in infix expressions - compiler AST output
|
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