|
|
@ -35,6 +35,15 @@ public class TokenList extends ArrayList<IToken> implements IToken { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create a tokenList with single item |
|
|
|
|
|
|
|
* @param token the item |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public TokenList(IToken token) { |
|
|
|
|
|
|
|
add(token); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Parse the token list.<br> |
|
|
|
* Parse the token list.<br> |
|
|
|
* After running this method, the list is typically reduced to a single |
|
|
|
* After running this method, the list is typically reduced to a single |
|
|
@ -121,29 +130,12 @@ public class TokenList extends ArrayList<IToken> implements IToken { |
|
|
|
|
|
|
|
|
|
|
|
TokenBinaryOperator opToken = (TokenBinaryOperator) operatorToken; |
|
|
|
TokenBinaryOperator opToken = (TokenBinaryOperator) operatorToken; |
|
|
|
|
|
|
|
|
|
|
|
// variables for tokenLists of the operands
|
|
|
|
// get operands
|
|
|
|
TokenList leftTL, rightTL; |
|
|
|
TokenList leftArg = get(pos - 1).wrapInTokenList(); |
|
|
|
|
|
|
|
TokenList rightArg = get(pos + 1).wrapInTokenList(); |
|
|
|
// get left operand
|
|
|
|
|
|
|
|
IToken leftArg = get(pos - 1); |
|
|
|
|
|
|
|
if (leftArg instanceof TokenList) { |
|
|
|
|
|
|
|
leftTL = (TokenList) leftArg; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
leftTL = new TokenList(1); |
|
|
|
|
|
|
|
leftTL.add(leftArg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get right operand
|
|
|
|
|
|
|
|
IToken rightArg = get(pos + 1); |
|
|
|
|
|
|
|
if (rightArg instanceof TokenList) { |
|
|
|
|
|
|
|
rightTL = (TokenList) rightArg; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
rightTL = new TokenList(1); |
|
|
|
|
|
|
|
rightTL.add(rightArg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// build an operation
|
|
|
|
// build an operation
|
|
|
|
Operation op = opToken.toOperation(leftTL, rightTL); |
|
|
|
Operation op = opToken.toOperation(leftArg, rightArg); |
|
|
|
|
|
|
|
|
|
|
|
// discard used tokens
|
|
|
|
// discard used tokens
|
|
|
|
subList(pos - 1, pos + 2).clear(); |
|
|
|
subList(pos - 1, pos + 2).clear(); |
|
|
@ -156,20 +148,11 @@ public class TokenList extends ArrayList<IToken> implements IToken { |
|
|
|
|
|
|
|
|
|
|
|
TokenUnaryOperatorLeft opToken = (TokenUnaryOperatorLeft) operatorToken; |
|
|
|
TokenUnaryOperatorLeft opToken = (TokenUnaryOperatorLeft) operatorToken; |
|
|
|
|
|
|
|
|
|
|
|
// variable for left operand
|
|
|
|
// get operand
|
|
|
|
TokenList leftTL; |
|
|
|
TokenList leftArg = get(pos - 1).wrapInTokenList(); |
|
|
|
|
|
|
|
|
|
|
|
// get left operand (the only one)
|
|
|
|
|
|
|
|
IToken leftArg = get(pos - 1); |
|
|
|
|
|
|
|
if (leftArg instanceof TokenList) { |
|
|
|
|
|
|
|
leftTL = (TokenList) leftArg; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
leftTL = new TokenList(1); |
|
|
|
|
|
|
|
leftTL.add(leftArg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// build an operation
|
|
|
|
// build an operation
|
|
|
|
Operation op = opToken.toOperation(leftTL); |
|
|
|
Operation op = opToken.toOperation(leftArg); |
|
|
|
|
|
|
|
|
|
|
|
// discard used tokens
|
|
|
|
// discard used tokens
|
|
|
|
subList(pos - 1, pos + 1).clear(); |
|
|
|
subList(pos - 1, pos + 1).clear(); |
|
|
@ -183,19 +166,10 @@ public class TokenList extends ArrayList<IToken> implements IToken { |
|
|
|
TokenUnaryOperatorRight opToken = (TokenUnaryOperatorRight) operatorToken; |
|
|
|
TokenUnaryOperatorRight opToken = (TokenUnaryOperatorRight) operatorToken; |
|
|
|
|
|
|
|
|
|
|
|
// variable for left operand
|
|
|
|
// variable for left operand
|
|
|
|
TokenList rightTL; |
|
|
|
TokenList rightArg = get(pos + 1).wrapInTokenList(); |
|
|
|
|
|
|
|
|
|
|
|
// get right operand (the only one)
|
|
|
|
|
|
|
|
IToken rightArg = get(pos + 1); |
|
|
|
|
|
|
|
if (rightArg instanceof TokenList) { |
|
|
|
|
|
|
|
rightTL = (TokenList) rightArg; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
rightTL = new TokenList(1); |
|
|
|
|
|
|
|
rightTL.add(rightArg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// build an operation
|
|
|
|
// build an operation
|
|
|
|
Operation op = opToken.toOperation(rightTL); |
|
|
|
Operation op = opToken.toOperation(rightArg); |
|
|
|
|
|
|
|
|
|
|
|
// discard used tokens
|
|
|
|
// discard used tokens
|
|
|
|
subList(pos, pos + 2).clear(); |
|
|
|
subList(pos, pos + 2).clear(); |
|
|
@ -265,4 +239,10 @@ public class TokenList extends ArrayList<IToken> implements IToken { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public TokenList wrapInTokenList() { |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|