From f028ea6dc555fc5192a96b00b8e96e90dbf6de55 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Mon, 9 Oct 2017 16:02:10 -0300 Subject: TODO tagging --- dice-lang/src/bjc/dicelang/expr/Shunter.java | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'dice-lang/src/bjc/dicelang/expr/Shunter.java') diff --git a/dice-lang/src/bjc/dicelang/expr/Shunter.java b/dice-lang/src/bjc/dicelang/expr/Shunter.java index 3e49356..213e473 100644 --- a/dice-lang/src/bjc/dicelang/expr/Shunter.java +++ b/dice-lang/src/bjc/dicelang/expr/Shunter.java @@ -11,6 +11,11 @@ import java.util.List; * @author Ben Culkin */ public class Shunter { + /* + * @NOTE + * Why does this method return an array, and not the list of + * tokens? + */ /** * Convert a infix series of tokens to a postfix series of tokens. * @@ -20,26 +25,27 @@ public class Shunter { * @return The tokens in postfix order. */ public static Token[] shuntTokens(final Token[] infixTokens) { + /* The returned tokens. */ final List postfixTokens = new ArrayList<>(infixTokens.length); + /* The current stack of operators. */ final Deque opStack = new LinkedList<>(); - /* - * Shunt each token. - */ + /* Shunt each token. */ for (final Token tok : infixTokens) { - /* - * Handle operators. - */ + /* Handle operators. */ if (tok.typ.isOperator) { Token curOp = opStack.peek(); /* * Check if an operator is higher priority, * respecting their left associativity. + * + * @NOTE + * Should this be factored out into a + * method? */ int leftPriority = tok.typ.operatorPriority; - int rightPriority; if (curOp == null) { @@ -56,11 +62,9 @@ public class Shunter { */ while (!opStack.isEmpty() && isHigherPrec) { postfixTokens.add(opStack.pop()); - curOp = opStack.peek(); leftPriority = tok.typ.operatorPriority; - if (curOp == null) { rightPriority = 0; } else { @@ -82,9 +86,7 @@ public class Shunter { */ while (curOp.typ != TokenType.OPAREN) { final Token tk = opStack.pop(); - postfixTokens.add(tk); - curOp = opStack.peek(); } @@ -105,4 +107,4 @@ public class Shunter { return postfixTokens.toArray(new Token[0]); } -} \ No newline at end of file +} -- cgit v1.2.3