/// <summary>
        /// Rewind the current state of the tree walk to the state it
        /// was in when Mark() was called and it returned marker.  Also,
        /// wipe out the lookahead which will force reloading a few nodes
        /// but it is better than making a copy of the lookahead buffer
        /// upon Mark().
        /// </summary>
        public virtual void Rewind(int marker)
        {
            if (markers == null)
            {
                return;
            }
            TreeWalkState state = (TreeWalkState)markers[marker];

            absoluteNodeIndex = state.absoluteNodeIndex;
            currentChildIndex = state.currentChildIndex;
            currentNode       = state.currentNode;
            previousNode      = state.previousNode;
            // drop node and index stacks back to old size
            nodeStack.Capacity  = state.nodeStackSize;
            indexStack.Capacity = state.indexStackSize;
            head = tail = 0;             // wack lookahead buffer and then refill
            for (; tail < state.lookahead.Length; tail++)
            {
                lookahead[tail] = state.lookahead[tail];
            }
            Release(marker);
        }
        /// <summary>
        /// Record the current state of the tree walk which includes
        /// the current node and stack state as well as the lookahead
        /// buffer.
        /// </summary>
        public virtual int Mark()
        {
            if (markers == null)
            {
                markers = new ArrayList();
                markers.Add(null);                 // depth 0 means no backtracking, leave blank
            }
            markDepth++;
            TreeWalkState state = null;

            if (markDepth >= markers.Count)
            {
                state = new TreeWalkState();
                markers.Add(state);
            }
            else
            {
                state = (TreeWalkState)markers[markDepth];
            }
            state.absoluteNodeIndex = absoluteNodeIndex;
            state.currentChildIndex = currentChildIndex;
            state.currentNode       = currentNode;
            state.previousNode      = previousNode;
            state.nodeStackSize     = nodeStack.Count;
            state.indexStackSize    = indexStack.Count;
            // take snapshot of lookahead buffer
            int n = LookaheadSize;
            int i = 0;

            state.lookahead = new object[n];
            for (int k = 1; k <= n; k++, i++)
            {
                state.lookahead[i] = LT(k);
            }
            lastMarker = markDepth;
            return(markDepth);
        }
        /// <summary>
        /// Record the current state of the tree walk which includes
        /// the current node and stack state as well as the lookahead
        /// buffer.
        /// </summary>
        public virtual int Mark()
        {
            if (markers == null)
            {
                markers = new ArrayList();
                markers.Add(null); // depth 0 means no backtracking, leave blank
            }
            markDepth++;
            TreeWalkState state = null;
            if ( markDepth >= markers.Count )
            {
                state = new TreeWalkState();
                markers.Add(state);
            }
            else
            {
                state = (TreeWalkState)markers[markDepth];

            }
            state.absoluteNodeIndex = absoluteNodeIndex;
            state.currentChildIndex = currentChildIndex;
            state.currentNode = currentNode;
            state.previousNode = previousNode;
            state.nodeStackSize = nodeStack.Count;
            state.indexStackSize = indexStack.Count;
            // take snapshot of lookahead buffer
            int n = LookaheadSize;
            int i = 0;
            state.lookahead = new object[n];
            for (int k = 1; k <= n; k++, i++)
            {
                state.lookahead[i] = LT(k);
            }
            lastMarker = markDepth;
            return markDepth;
        }