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': case 'o':
if (expressionStart) { if (expressionStart) {
// Preprocess prefix operators into unary operators
halfProcessed.add(new UnaryOperator((OperatorToken) current)); halfProcessed.add(new UnaryOperator((OperatorToken) current));
} else { } else {
halfProcessed.add(current); halfProcessed.add(current);

Datei anzeigen

@ -220,7 +220,7 @@ public final class ParserProcessors {
} }
private static RValue processUnaryOps(LinkedList<Identifiable> input) throws ParserException { private static RValue processUnaryOps(LinkedList<Identifiable> input) throws ParserException {
// Preprocess postfix operators into prefix operators // Preprocess postfix operators into unary operators
final Identifiable center; final Identifiable center;
LinkedList<UnaryOperator> postfixes = new LinkedList<UnaryOperator>(); LinkedList<UnaryOperator> postfixes = new LinkedList<UnaryOperator>();
do { do {
@ -230,12 +230,10 @@ public final class ParserProcessors {
final Identifiable last = input.removeLast(); final Identifiable last = input.removeLast();
if (last instanceof OperatorToken) { if (last instanceof OperatorToken) {
System.out.println("Found postfix: "+last); postfixes.addLast(new UnaryOperator(last.getPosition(), "x"+((OperatorToken)last).operator));
postfixes.addFirst(new UnaryOperator(last.getPosition(), "x"+((OperatorToken)last).operator));
} }
else if (last instanceof UnaryOperator) { else if (last instanceof UnaryOperator) {
System.out.println("Found postfix: "+last); postfixes.addLast(new UnaryOperator(last.getPosition(), "x"+((UnaryOperator)last).operator));
postfixes.addFirst(new UnaryOperator(last.getPosition(), "x"+((UnaryOperator)last).operator));
} }
else { else {
center = last; center = last;
@ -269,6 +267,7 @@ public final class ParserProcessors {
} }
} }
} }
if (last instanceof Token) { if (last instanceof Token) {
throw new ParserException(lastPosition, "Extra token found in expression: " + last); throw new ParserException(lastPosition, "Extra token found in expression: " + last);
} else if (last instanceof RValue) { } else if (last instanceof RValue) {