/** * Returns the amount of space required to flatten the given sub-array of symbols. * * @param symbols The array of input symbols. * @param start The index where the subarray starts. * @return The number of symbols that will be produced if one expands the given input. */ protected static int flattenedSize(Symbol[] symbols, int start) { int result = 0; for (int i = start; i < symbols.length; i++) { if (symbols[i] instanceof Sequence) { Sequence s = (Sequence) symbols[i]; result += s.flattenedSize(); } else { result += 1; } } return result; }