summaryrefslogtreecommitdiff
path: root/base/src/bjc/dicelang/expr/Shunter.java
diff options
context:
space:
mode:
authorbjculkin <bjculkin@mix.wvu.edu>2018-03-01 19:13:48 -0500
committerbjculkin <bjculkin@mix.wvu.edu>2018-03-01 19:13:48 -0500
commitf9d9bd4bbf7dd6a297e1daf5ee7b4263d706d9cd (patch)
tree75ade2ca798bcdbdd7daf867480378299598581a /base/src/bjc/dicelang/expr/Shunter.java
parentb14a399d05fc90d8532cd08d1546e6bf197db10e (diff)
Update
Diffstat (limited to 'base/src/bjc/dicelang/expr/Shunter.java')
-rw-r--r--base/src/bjc/dicelang/expr/Shunter.java34
1 files changed, 19 insertions, 15 deletions
diff --git a/base/src/bjc/dicelang/expr/Shunter.java b/base/src/bjc/dicelang/expr/Shunter.java
index 53c2298..3d2a523 100644
--- a/base/src/bjc/dicelang/expr/Shunter.java
+++ b/base/src/bjc/dicelang/expr/Shunter.java
@@ -16,7 +16,7 @@ public class Shunter {
* Convert a infix series of tokens to a postfix series of tokens.
*
* @param infixTokens
- * The tokens in infix order.
+ * The tokens in infix order.
*
* @return The tokens in postfix order.
*/
@@ -28,20 +28,22 @@ public class Shunter {
final Deque<Token> opStack = new LinkedList<>();
/* Shunt each token. */
- for (final Token tok : infixTokens) {
+ for(final Token tok : infixTokens) {
/* Handle operators. */
- if (tok.typ.isOperator) {
+ if(tok.typ.isOperator) {
Token curOp = opStack.peek();
/*
- * Check if an operator is higher priority, respecting their left associativity.
+ * Check if an operator is higher priority,
+ * respecting their left associativity.
*
- * @NOTE Should this be factored out into a method?
+ * @NOTE Should this be factored out into a
+ * method?
*/
int leftPriority = tok.typ.operatorPriority;
int rightPriority;
- if (curOp == null) {
+ if(curOp == null) {
rightPriority = 0;
} else {
rightPriority = curOp.typ.operatorPriority;
@@ -50,14 +52,15 @@ public class Shunter {
boolean isHigherPrec = leftPriority >= rightPriority;
/*
- * Pop all operators that are lower precedence than us.
+ * Pop all operators that are lower precedence
+ * than us.
*/
- while (!opStack.isEmpty() && isHigherPrec) {
+ while(!opStack.isEmpty() && isHigherPrec) {
postfixTokens.add(opStack.pop());
curOp = opStack.peek();
leftPriority = tok.typ.operatorPriority;
- if (curOp == null) {
+ if(curOp == null) {
rightPriority = 0;
} else {
rightPriority = curOp.typ.operatorPriority;
@@ -67,21 +70,22 @@ public class Shunter {
}
opStack.push(tok);
- } else if (tok.typ == TokenType.OPAREN) {
+ } else if(tok.typ == TokenType.OPAREN) {
opStack.push(tok);
- } else if (tok.typ == TokenType.CPAREN) {
+ } else if(tok.typ == TokenType.CPAREN) {
Token curOp = opStack.peek();
/*
- * Pop things until we find the matching parenthesis.
+ * Pop things until we find the matching
+ * parenthesis.
*/
- while (curOp.typ != TokenType.OPAREN) {
+ while(curOp.typ != TokenType.OPAREN) {
final Token tk = opStack.pop();
postfixTokens.add(tk);
curOp = opStack.peek();
}
- if (!opStack.isEmpty()) {
+ if(!opStack.isEmpty()) {
opStack.pop();
}
} else {
@@ -92,7 +96,7 @@ public class Shunter {
/*
* Flush remaining operators.
*/
- while (!opStack.isEmpty()) {
+ while(!opStack.isEmpty()) {
postfixTokens.add(opStack.pop());
}