private int executeOperator( int operatorIndex, final OperatorType operatorType, int operandCount, Map<Integer, DelegateTokenType> index2DelegateType) { Token<?> token = null; operandCount += index2DelegateType.size(); // check if literal expression can be executed boolean canExecute = true; // operand count int count = 0; // operand start index int operandStartIndex = -1; for (int j = operatorIndex - 1; j >= 0; j--) { token = this.tokenList.get(j); if (token == null) { // we must compact token list and retry executing return -1; } final TokenType tokenType = token.getType(); // Check if operand is a literal operand if (!this.isLiteralOperand(token, tokenType, count + 1, index2DelegateType)) { canExecute = false; break; } count++; if (count == operandCount) { operandStartIndex = j; break; } } // if we can execute it on compile if (canExecute) { // arguments AviatorObject[] args = new AviatorObject[operandCount]; int index = 0; for (int j = operandStartIndex; j < operatorIndex; j++) { token = this.tokenList.get(j); if (token.getType() == TokenType.Delegate) { this.tokenList.set(j, null); continue; } args[index++] = this.getAviatorObjectFromToken(token); // set argument token to null this.tokenList.set(j, null); } // execute it now AviatorObject result = operatorType.eval(args); // set result as token to tokenList for next executing this.tokenList.set(operatorIndex, this.getTokenFromOperand(result)); return 1; } return 0; }