ExpressionBuilder: Let operators decide how many operands to push back.
1 files changed, 63 insertions(+), 63 deletions(-)

M src/main/java/nl/grauw/glass/expressions/ExpressionBuilder.java
M src/main/java/nl/grauw/glass/expressions/ExpressionBuilder.java +63 -63
@@ 62,7 62,7 @@ public class ExpressionBuilder {
 
 	private void evaluateNotYieldingTo(Operator operator) {
 		while (!operators.peek().yieldsTo(operator))
-			operands.push(operators.pop().evaluate());
+			operators.pop().evaluate();
 	}
 
 	public boolean hasOpenGroup()

          
@@ 93,7 93,7 @@ public class ExpressionBuilder {
 				return precedence.ordinal() >= other.precedence.ordinal();
 		}
 
-		public abstract Expression evaluate();
+		public abstract void evaluate();
 
 		@Override
 		public String toString() {

          
@@ 103,223 103,223 @@ public class ExpressionBuilder {
 
 	public final Operator POSITIVE = new Operator(Precedence.UNARY, Associativity.RIGHT_TO_LEFT, "+") {
 		@Override
-		public Expression evaluate() {
-			return new Positive(operands.pop());
+		public void evaluate() {
+			operands.push(new Positive(operands.pop()));
 		};
 	};
 
 	public final Operator NEGATIVE = new Operator(Precedence.UNARY, Associativity.RIGHT_TO_LEFT, "-") {
 		@Override
-		public Expression evaluate() {
-			return new Negative(operands.pop());
+		public void evaluate() {
+			operands.push(new Negative(operands.pop()));
 		};
 	};
 
 	public final Operator COMPLEMENT = new Operator(Precedence.UNARY, Associativity.RIGHT_TO_LEFT, "~") {
 		@Override
-		public Expression evaluate() {
-			return new Complement(operands.pop());
+		public void evaluate() {
+			operands.push(new Complement(operands.pop()));
 		};
 	};
 
 	public final Operator NOT = new Operator(Precedence.UNARY, Associativity.RIGHT_TO_LEFT, "!") {
 		@Override
-		public Expression evaluate() {
-			return new Not(operands.pop());
+		public void evaluate() {
+			operands.push(new Not(operands.pop()));
 		};
 	};
 
 	public final Operator MEMBER = new Operator(Precedence.MEMBER, Associativity.LEFT_TO_RIGHT, ".") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
 			if (!(operandRight instanceof Identifier))
 				throw new ExpressionError("Member operator right hand side must be an identifier.");
-			return new Member(operands.pop(), (Identifier)operandRight);
+			operands.push(new Member(operands.pop(), (Identifier)operandRight));
 		};
 	};
 
 	public final Operator MULTIPLY = new Operator(Precedence.MULTIPLICATION, Associativity.LEFT_TO_RIGHT, "*") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new Multiply(operands.pop(), operandRight);
+			operands.push(new Multiply(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator DIVIDE = new Operator(Precedence.MULTIPLICATION, Associativity.LEFT_TO_RIGHT, "/") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new Divide(operands.pop(), operandRight);
+			operands.push(new Divide(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator MODULO = new Operator(Precedence.MULTIPLICATION, Associativity.LEFT_TO_RIGHT, "%") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new Modulo(operands.pop(), operandRight);
+			operands.push(new Modulo(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator ADD = new Operator(Precedence.ADDITION, Associativity.LEFT_TO_RIGHT, "+") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new Add(operands.pop(), operandRight);
+			operands.push(new Add(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator SUBTRACT = new Operator(Precedence.ADDITION, Associativity.LEFT_TO_RIGHT, "-") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new Subtract(operands.pop(), operandRight);
+			operands.push(new Subtract(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator SHIFT_LEFT = new Operator(Precedence.SHIFT, Associativity.LEFT_TO_RIGHT, "<<") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new ShiftLeft(operands.pop(), operandRight);
+			operands.push(new ShiftLeft(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator SHIFT_RIGHT = new Operator(Precedence.SHIFT, Associativity.LEFT_TO_RIGHT, ">>") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new ShiftRight(operands.pop(), operandRight);
+			operands.push(new ShiftRight(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator LESS_THAN = new Operator(Precedence.COMPARISON, Associativity.LEFT_TO_RIGHT, "<") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new LessThan(operands.pop(), operandRight);
+			operands.push(new LessThan(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator LESS_OR_EQUALS = new Operator(Precedence.COMPARISON, Associativity.LEFT_TO_RIGHT, "<=") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new LessOrEquals(operands.pop(), operandRight);
+			operands.push(new LessOrEquals(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator GREATER_THAN = new Operator(Precedence.COMPARISON, Associativity.LEFT_TO_RIGHT, ">") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new GreaterThan(operands.pop(), operandRight);
+			operands.push(new GreaterThan(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator GREATER_OR_EQUALS = new Operator(Precedence.COMPARISON, Associativity.LEFT_TO_RIGHT, ">=") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new GreaterOrEquals(operands.pop(), operandRight);
+			operands.push(new GreaterOrEquals(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator EQUALS = new Operator(Precedence.EQUALITY, Associativity.LEFT_TO_RIGHT, "=") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new Equals(operands.pop(), operandRight);
+			operands.push(new Equals(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator NOT_EQUALS = new Operator(Precedence.EQUALITY, Associativity.LEFT_TO_RIGHT, "!=") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new NotEquals(operands.pop(), operandRight);
+			operands.push(new NotEquals(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator AND = new Operator(Precedence.AND, Associativity.LEFT_TO_RIGHT, "&") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new And(operands.pop(), operandRight);
+			operands.push(new And(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator XOR = new Operator(Precedence.XOR, Associativity.LEFT_TO_RIGHT, "^") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new Xor(operands.pop(), operandRight);
+			operands.push(new Xor(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator OR = new Operator(Precedence.OR, Associativity.LEFT_TO_RIGHT, "|") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new Or(operands.pop(), operandRight);
+			operands.push(new Or(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator LOGICAL_AND = new Operator(Precedence.LOGICAL_AND, Associativity.LEFT_TO_RIGHT, "&&") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new LogicalAnd(operands.pop(), operandRight);
+			operands.push(new LogicalAnd(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator LOGICAL_OR = new Operator(Precedence.LOGICAL_OR, Associativity.LEFT_TO_RIGHT, "||") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new LogicalOr(operands.pop(), operandRight);
+			operands.push(new LogicalOr(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator ANNOTATION = new Operator(Precedence.ANNOTATION, Associativity.RIGHT_TO_LEFT, " ") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
 			Expression operandLeft = operands.pop();
 			if (!(operandLeft instanceof Identifier))
 				throw new ExpressionError("Annotation left hand side must be an identifier.");
-			return new Annotation((Identifier)operandLeft, operandRight);
+			operands.push(new Annotation((Identifier)operandLeft, operandRight));
 		};
 	};
 
 	public final Operator SEQUENCE = new Operator(Precedence.SEQUENCE, Associativity.RIGHT_TO_LEFT, ",") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new Sequence(operands.pop(), operandRight);
+			operands.push(new Sequence(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator TERNARYIF = new Operator(Precedence.TERNARYIFELSE, Associativity.RIGHT_TO_LEFT, "?") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			throw new ExpressionError("Ternary if (?) without else (:).");
 		};
 	};
 
 	public final Operator TERNARYELSE = new Operator(Precedence.TERNARYIFELSE, Associativity.RIGHT_TO_LEFT, ":") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
 			while (operators.peek() == TERNARYELSE) {
-				operands.push(operators.pop().evaluate());
+				operators.pop().evaluate();
 			}
 			if (operators.peek() == TERNARYIF) {
 				operators.pop();
 				Expression operandMiddle = operands.pop();
-				return new IfElse(operands.pop(), operandMiddle, operandRight);
+				operands.push(new IfElse(operands.pop(), operandMiddle, operandRight));
 			} else {
 				throw new ExpressionError("Ternary else (:) without if (?).");
 			}

          
@@ 328,36 328,36 @@ public class ExpressionBuilder {
 
 	public final Operator GROUP_OPEN = new Operator(Precedence.GROUPING, Associativity.LEFT_TO_RIGHT, "(") {
 		@Override
-		public Expression evaluate() {
-			return new Group(operands.pop());
+		public void evaluate() {
+			operands.push(new Group(operands.pop()));
 		};
 	};
 
 	public final Operator GROUP_CLOSE = new Operator(Precedence.NONE, Associativity.LEFT_TO_RIGHT, ")") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			throw new AssemblyException("Can not evaluate group close.");
 		};
 	};
 
 	public final Operator INDEX_OPEN = new Operator(Precedence.MEMBER, Associativity.LEFT_TO_RIGHT, "[") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			Expression operandRight = operands.pop();
-			return new Index(operands.pop(), operandRight);
+			operands.push(new Index(operands.pop(), operandRight));
 		};
 	};
 
 	public final Operator INDEX_CLOSE = new Operator(Precedence.NONE, Associativity.LEFT_TO_RIGHT, "]") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			throw new AssemblyException("Can not evaluate index close.");
 		};
 	};
 
 	public final Operator SENTINEL = new Operator(Precedence.NONE, Associativity.RIGHT_TO_LEFT, "#") {
 		@Override
-		public Expression evaluate() {
+		public void evaluate() {
 			throw new AssemblyException("Can not evaluate sentinel.");
 		};
 	};