private static int rpnParse(Object[] parsedQuery, int position) throws ParseException {
        Object curr = parsedQuery[position];
        int tokens = 1;
        if (curr instanceof Expression) {
            int numArgs = ((Expression) curr).getArgumentCount();
            List args = new ArrayList(numArgs);
            for (int a = 0; a < numArgs; a++) {
                int currArgIndex = position + tokens;
                if ((currArgIndex) >= parsedQuery.length) {
                    throw new ParseException("Token at position " + position + " has argument " + (a+1) + " of " + numArgs + " which is calculated to be at position " + currArgIndex + ", which beyond the parsed list of query tokens");
                }
                tokens += rpnParse(parsedQuery, currArgIndex);
                args.add(new Integer(currArgIndex));
            }
            if (curr instanceof Operator) {
                Operator op = (Operator) curr;
                Expression[] eargs = new Expression[numArgs];
                for(int a = 0; a < numArgs; a++) {
                    Integer index = (Integer) args.get(a);
                    Object arg = parsedQuery[index.intValue()];
                    if (!(arg instanceof Expression))
                        throw new ParseException("Token at position " + position + " has argument " + (a+1) + " of " + numArgs + ", calculated to be at position " + index + ", which is expected to be an expression token, but is instead a literal string: " + arg);
                    eargs[a] = (Expression) arg;
                }
                op.setChildExpressions(eargs);
            }
            else if (curr instanceof Function) {
                Function func = (Function) curr;
                String[] sargs = new String[numArgs];
                for(int a = 0; a < numArgs; a++) {
                    Integer index = (Integer) args.get(a);
                    Object arg = parsedQuery[index.intValue()];
                    if (arg instanceof Expression)
                        throw new ParseException("Token at position " + position + " has argument " + (a+1) + " of " + numArgs + ", calculated to be at position " + index + ", which is expected to be literal string, but is instead an expression token: " + arg);
                    sargs[a] = arg.toString();
                }
                func.setArguments(sargs);
            }
        }
        return tokens;
    }