Community
Participate
Working Groups
In the Java AST, the InfixExpression AST node is allowed to have more than 2 operands, where the one operator is applied to all. However, this flattening is not always performed. See the trees below. A - operation followed by many + operations is not flattened, whereas many + followed by a - is flattened. (I actually found it a pain to coerce my parser to reproduce this - it would have been easier just to compare the current operator with the operator from the previous (LH) operand - if the same, combine; if not, make a new Infix node) TREES FOR class A { int i = 1 - 2 + 3 + 4 + 5; int j = 1 + 2 + 3 + 4 - 5; } ECLIPSE AST 0) class org.eclipse.jdt.core.dom.CompilationUnit 0 65 1) class org.eclipse.jdt.core.dom.TypeDeclaration 0 65 interface = false 2) class org.eclipse.jdt.core.dom.SimpleName 6 1 identifier = A 3) class org.eclipse.jdt.core.dom.FieldDeclaration 10 26 4) class org.eclipse.jdt.core.dom.PrimitiveType 10 3 primitiveTypeCode = int 5) class org.eclipse.jdt.core.dom.VariableDeclarationFragment 14 21 extraDimensions = 0 6) class org.eclipse.jdt.core.dom.SimpleName 14 1 identifier = i 7) class org.eclipse.jdt.core.dom.InfixExpression 18 17 operator = + 8) class org.eclipse.jdt.core.dom.InfixExpression 18 13 operator = + 9) class org.eclipse.jdt.core.dom.InfixExpression 18 9 operator = + 10) class org.eclipse.jdt.core.dom.InfixExpression 18 5 operator = - 11) class org.eclipse.jdt.core.dom.NumberLiteral 18 1 token = 1 12) class org.eclipse.jdt.core.dom.NumberLiteral 22 1 token = 2 13) class org.eclipse.jdt.core.dom.NumberLiteral 26 1 token = 3 14) class org.eclipse.jdt.core.dom.NumberLiteral 30 1 token = 4 15) class org.eclipse.jdt.core.dom.NumberLiteral 34 1 token = 5 16) class org.eclipse.jdt.core.dom.FieldDeclaration 37 26 17) class org.eclipse.jdt.core.dom.PrimitiveType 37 3 primitiveTypeCode = int 18) class org.eclipse.jdt.core.dom.VariableDeclarationFragment 41 21 extraDimensions = 0 19) class org.eclipse.jdt.core.dom.SimpleName 41 1 identifier = j 20) class org.eclipse.jdt.core.dom.InfixExpression 45 17 operator = - 21) class org.eclipse.jdt.core.dom.InfixExpression 45 13 operator = + 22) class org.eclipse.jdt.core.dom.NumberLiteral 45 1 token = 1 23) class org.eclipse.jdt.core.dom.NumberLiteral 49 1 token = 2 24) class org.eclipse.jdt.core.dom.NumberLiteral 53 1 token = 3 25) class org.eclipse.jdt.core.dom.NumberLiteral 57 1 token = 4 26) class org.eclipse.jdt.core.dom.NumberLiteral 61 1 token = 5
For 1 - 2 + 3 + 4 + 5, are you expecting to get an infix expression with: -left: an infix expression that contains (1 - 2) - rigth: 3 - extended operands: 4, 5 ?
(In reply to comment #1) > For 1 - 2 + 3 + 4 + 5, are you expecting to get an infix expression with: > -left: an infix expression that contains (1 - 2) > - rigth: 3 > - extended operands: 4, 5 > ? Yes (and sorry I missed this comment when it was originally made).
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.