summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/expr/Shunter.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2017-04-11 21:48:50 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2017-04-11 21:48:50 -0400
commit57f9a3bfdad20bead5b35ee540e8790e80a6b9a4 (patch)
tree1e7184825eaa8d22077b505513df3e0d8502fb39 /dice-lang/src/bjc/dicelang/expr/Shunter.java
parent675ae734dd7b7a47d93ee3527dd1eb7195be047b (diff)
Cleanup
Diffstat (limited to 'dice-lang/src/bjc/dicelang/expr/Shunter.java')
-rw-r--r--dice-lang/src/bjc/dicelang/expr/Shunter.java36
1 files changed, 18 insertions, 18 deletions
diff --git a/dice-lang/src/bjc/dicelang/expr/Shunter.java b/dice-lang/src/bjc/dicelang/expr/Shunter.java
index 3b2bee2..19b30c3 100644
--- a/dice-lang/src/bjc/dicelang/expr/Shunter.java
+++ b/dice-lang/src/bjc/dicelang/expr/Shunter.java
@@ -19,32 +19,32 @@ public class Shunter {
*
* @return The tokens in postfix order.
*/
- public static Token[] shuntTokens(Token[] infixTokens) {
- List<Token> postfixTokens = new ArrayList<>(infixTokens.length);
+ public static Token[] shuntTokens(final Token[] infixTokens) {
+ final List<Token> postfixTokens = new ArrayList<>(infixTokens.length);
- Deque<Token> opStack = new LinkedList<>();
+ final Deque<Token> opStack = new LinkedList<>();
/*
* Shunt each token.
*/
- for(Token tok : infixTokens) {
+ for (final Token tok : infixTokens) {
/*
* Handle operators.
*/
- if(tok.type.isOperator) {
+ if (tok.typ.isOperator) {
Token curOp = opStack.peek();
/*
* Check if an operator is higher priority,
* respecting their left associativity.
*/
- int leftPriority = tok.type.operatorPriority;
+ int leftPriority = tok.typ.operatorPriority;
int rightPriority;
- if(curOp == null) {
+ if (curOp == null) {
rightPriority = 0;
} else {
- rightPriority = curOp.type.operatorPriority;
+ rightPriority = curOp.typ.operatorPriority;
}
boolean isHigherPrec = leftPriority >= rightPriority;
@@ -53,41 +53,41 @@ public class Shunter {
* 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.type.operatorPriority;
+ leftPriority = tok.typ.operatorPriority;
- if(curOp == null) {
+ if (curOp == null) {
rightPriority = 0;
} else {
- rightPriority = curOp.type.operatorPriority;
+ rightPriority = curOp.typ.operatorPriority;
}
isHigherPrec = leftPriority >= rightPriority;
}
opStack.push(tok);
- } else if(tok.type == TokenType.OPAREN) {
+ } else if (tok.typ == TokenType.OPAREN) {
opStack.push(tok);
- } else if(tok.type == TokenType.CPAREN) {
+ } else if (tok.typ == TokenType.CPAREN) {
Token curOp = opStack.peek();
/*
* Pop things until we find the matching
* parenthesis.
*/
- while(curOp.type != TokenType.OPAREN) {
- Token tk = opStack.pop();
+ 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 {
@@ -98,7 +98,7 @@ public class Shunter {
/*
* Flush remaining operators.
*/
- while(!opStack.isEmpty()) {
+ while (!opStack.isEmpty()) {
postfixTokens.add(opStack.pop());
}