Fixed postfix operator evaluation order.

Dieser Commit ist enthalten in:
TomyLobo 2011-10-31 00:38:59 +01:00
Ursprung d5328e34ba
Commit d3822ee345
2 geänderte Dateien mit 5 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -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);

Datei anzeigen

@ -220,7 +220,7 @@ public final class ParserProcessors {
}
private static RValue processUnaryOps(LinkedList<Identifiable> input) throws ParserException {
// Preprocess postfix operators into prefix operators
// Preprocess postfix operators into unary operators
final Identifiable center;
LinkedList<UnaryOperator> postfixes = new LinkedList<UnaryOperator>();
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) {