private void extractParentheses() {

		int open = 0; // level of outer parentheses
		int openIgnored = 0; // level of inner parentheses, to be skipped

		Stack<Integer> lefts = new Stack<Integer>();
		Stack<Integer> rights = new Stack<Integer>();

		for (int i = 0; i < size(); i++) {

			if (get(i) instanceof TokenParenthesisLeft) {

				if (open == 0) {
					open++;
					lefts.push(i);
				} else {
					openIgnored++;
				}
			}

			if (get(i) instanceof TokenParenthesisRight) {

				if (openIgnored > 0) {
					openIgnored--;
				} else {
					open--;
					if (open == 0) rights.push(i);
				}
			}
		}

		if (open > 0) throw new ParseError("Unbalanced parentheses.");

		// extract token lists inside the outer parentheses, put them back as single tokens
		while (!lefts.isEmpty()) {
			int left = lefts.pop();
			int right = rights.pop();

			int innerLeft = left + 1;
			int innerRight = right - 1;

			// prepare tokenList for the inner tokens
			TokenList insides = new TokenList();
			// add the inner tokens
			insides.addAll(subList(innerLeft, innerRight + 1));
			// destroy the whole range including parentheses
			subList(left, right + 1).clear();
			// put replacement token back
			add(left, insides.parse());
		}

	}