summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/expr/Shunter.java
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-10-09 16:02:10 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-10-09 16:02:10 -0300
commitf028ea6dc555fc5192a96b00b8e96e90dbf6de55 (patch)
tree4b2a28ecbeb30095b50e6e9e8ac8b98fa8ddc79e /dice-lang/src/bjc/dicelang/expr/Shunter.java
parentbe4675f9512060aa85b1e0a4f223208b51b55812 (diff)
TODO tagging
Diffstat (limited to 'dice-lang/src/bjc/dicelang/expr/Shunter.java')
-rw-r--r--dice-lang/src/bjc/dicelang/expr/Shunter.java26
1 files changed, 14 insertions, 12 deletions
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<Token> postfixTokens = new ArrayList<>(infixTokens.length);
+ /* The current stack of operators. */
final Deque<Token> 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
+}