Esempio n. 1
0
        internal virtual State.HeadPosition GetSeparator(int nodeNum)
        {
            if (nodeNum >= stack.Size())
            {
                return(null);
            }
            TreeShapedStack <Tree> stack = this.stack;

            for (int i = 0; i < nodeNum; ++i)
            {
                stack = stack.Pop();
            }
            Tree node = stack.Peek();
            int  head = ShiftReduceUtils.HeadIndex(node);

            if (separators[head] != null)
            {
                return(State.HeadPosition.Head);
            }
            int  left      = ShiftReduceUtils.LeftIndex(node);
            int  nextLeft  = separators.FloorKey(head);
            bool hasLeft   = (nextLeft != null && nextLeft >= left);
            int  right     = ShiftReduceUtils.RightIndex(node);
            int  nextRight = separators.CeilingKey(head);
            bool hasRight  = (nextRight != null && nextRight <= right);

            if (hasLeft && hasRight)
            {
                return(State.HeadPosition.Both);
            }
            else
            {
                if (hasLeft)
                {
                    return(State.HeadPosition.Left);
                }
                else
                {
                    if (hasRight)
                    {
                        return(State.HeadPosition.Right);
                    }
                    else
                    {
                        return(State.HeadPosition.None);
                    }
                }
            }
        }
Esempio n. 2
0
        internal virtual string GetSeparatorBetween(Tree right, Tree left)
        {
            if (right == null || left == null)
            {
                return(null);
            }
            int leftHead  = ShiftReduceUtils.HeadIndex(left);
            int rightHead = ShiftReduceUtils.HeadIndex(right);
            KeyValuePair <int, string> nextSeparator = separators.CeilingEntry(leftHead);

            if (nextSeparator == null || nextSeparator.Key > rightHead)
            {
                return(null);
            }
            return(Sharpen.Runtime.Substring(nextSeparator.Value, 0, 1));
        }
Esempio n. 3
0
        internal virtual int GetSeparatorCount(Tree right, Tree left)
        {
            if (right == null || left == null)
            {
                return(0);
            }
            int leftHead      = ShiftReduceUtils.HeadIndex(left);
            int rightHead     = ShiftReduceUtils.HeadIndex(right);
            int nextSeparator = separators.HigherKey(leftHead);
            int count         = 0;

            while (nextSeparator != null && nextSeparator < rightHead)
            {
                ++count;
                nextSeparator = separators.HigherKey(nextSeparator);
            }
            return(count);
        }