From d3822ee345758d328cb68543e885553e4a41558a Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Mon, 31 Oct 2011 00:38:59 +0100 Subject: [PATCH] Fixed postfix operator evaluation order. --- .../com/sk89q/worldedit/expression/parser/Parser.java | 1 + .../worldedit/expression/parser/ParserProcessors.java | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/expression/parser/Parser.java b/src/main/java/com/sk89q/worldedit/expression/parser/Parser.java index f4d9afcae..6618b2ed0 100644 --- a/src/main/java/com/sk89q/worldedit/expression/parser/Parser.java +++ b/src/main/java/com/sk89q/worldedit/expression/parser/Parser.java @@ -166,6 +166,7 @@ public class Parser { case 'o': if (expressionStart) { + // Preprocess prefix operators into unary operators halfProcessed.add(new UnaryOperator((OperatorToken) current)); } else { halfProcessed.add(current); diff --git a/src/main/java/com/sk89q/worldedit/expression/parser/ParserProcessors.java b/src/main/java/com/sk89q/worldedit/expression/parser/ParserProcessors.java index 4a1c47dac..6814f985d 100644 --- a/src/main/java/com/sk89q/worldedit/expression/parser/ParserProcessors.java +++ b/src/main/java/com/sk89q/worldedit/expression/parser/ParserProcessors.java @@ -220,7 +220,7 @@ public final class ParserProcessors { } private static RValue processUnaryOps(LinkedList input) throws ParserException { - // Preprocess postfix operators into prefix operators + // Preprocess postfix operators into unary operators final Identifiable center; LinkedList postfixes = new LinkedList(); do { @@ -230,12 +230,10 @@ public final class ParserProcessors { final Identifiable last = input.removeLast(); if (last instanceof OperatorToken) { - System.out.println("Found postfix: "+last); - postfixes.addFirst(new UnaryOperator(last.getPosition(), "x"+((OperatorToken)last).operator)); + postfixes.addLast(new UnaryOperator(last.getPosition(), "x"+((OperatorToken)last).operator)); } else if (last instanceof UnaryOperator) { - System.out.println("Found postfix: "+last); - postfixes.addFirst(new UnaryOperator(last.getPosition(), "x"+((UnaryOperator)last).operator)); + postfixes.addLast(new UnaryOperator(last.getPosition(), "x"+((UnaryOperator)last).operator)); } else { center = last; @@ -269,6 +267,7 @@ public final class ParserProcessors { } } } + if (last instanceof Token) { throw new ParserException(lastPosition, "Extra token found in expression: " + last); } else if (last instanceof RValue) {