コード例 #1
0
ファイル: GssNode.cs プロジェクト: sucaba/IronTextLibrary
        public GssLink <T> AddLink(GssNode <T> leftNode, T label)
        {
            var result = new GssLink <T>(leftNode, label, firstLink);

            firstLink = result;
            return(result);
        }
コード例 #2
0
 public Reduction(GssNode <T> rightNode, Production rule, int size, int epsilonIndex, GssLink <T> rightLink)
 {
     this.Rule         = rule;
     this.RightNode    = rightNode;
     this.Token        = rule.OutcomeToken;
     this.Size         = size;
     this.EpsilonIndex = epsilonIndex;
     this.RightLink    = rightLink;
 }
コード例 #3
0
 public void Enqueue(GssLink <T> rightLink, Production rule, int size)
 {
     reductions.Enqueue(
         new Reduction <T>(
             rightLink.LeftNode,
             rule,
             size,
             -1,
             rightLink));
 }
コード例 #4
0
        public void Enqueue(GssLink <T> rightLink, Production rule, int size)
        {
            Debug.Assert(rightLink != null);

            int tail = size == 0 ? 0 : 1;

            GssReducePath <T> .GetAll(
                rightLink.LeftNode,
                size - tail,
                tail,
                rule,
                rightLink,
                InternalEnqueue);
        }
コード例 #5
0
ファイル: GssNode.cs プロジェクト: sucaba/IronTextLibrary
        T IStackLookback <T> .GetValueAt(int count)
        {
            GssNode <T> node = this;

            Debug.Assert(count > 0, "Lookback should be at least 1 token back");
            Debug.Assert(node.DeterministicDepth >= count, "Non-deterministic lookback.");

            GssLink <T> lastLink = null;
            GssNode <T> lastNode = null;

            do
            {
                lastNode = node;
                lastLink = node.FirstLink;
                node     = lastLink.LeftNode;
            }while (--count != 0);

            return(lastLink.Label);
        }
コード例 #6
0
        public static Msg GssLookback(object glrLookback, int count)
        {
            GssNode <Msg> node = (GssNode <Msg>)glrLookback;

            Debug.Assert(count > 0, "Lookback should be at least 1 token back");
            Debug.Assert(node.DeterministicDepth >= count, "Non-deterministic lookback.");

            GssLink <Msg> lastLink = null;
            GssNode <Msg> lastNode = null;

            do
            {
                lastNode = node;
                lastLink = node.FirstLink;
                node     = lastLink.LeftNode;
            }while (--count != 0);

            // Make new Msg to replace token Id with state Id
            return(new Msg(lastNode.State, lastLink.Label.Value, lastLink.Label.Location));
        }
コード例 #7
0
        public static void GetAll(
            GssNode <T> rightNode,
            int size,
            int tail,
            Production rule,
            GssLink <T> rightLink,
            Action <GssReducePath <T> > action0)
        {
            Action <GssReducePath <T> > action;

            if (tail == 0)
            {
                action = action0;
            }
            else
            {
                action = path =>
                {
                    path.Links[size] = rightLink;
                    action0(path);
                };
            }

            int fullSize = size + tail;

            if (size == 0)
            {
                action(new GssReducePath <T>(rightNode, new GssLink <T> [tail], rule, fullSize));
            }
            else if (size <= rightNode.DeterministicDepth)
            {
                var links = new GssLink <T> [fullSize];

                GssNode <T> node = rightNode;
                int         i    = size;
                while (i-- != 0)
                {
                    var link = node.FirstLink;
                    links[i] = link;

                    node = link.LeftNode;
                }

                action(new GssReducePath <T>(node, links, rule, fullSize));
            }
            else
            {
                // TODO: Get rid of front. 'front link' is frontPaths[j][k]
                var front      = new List <GssLink <T> >(2);
                var frontPaths = new List <GssLink <T>[]>(rightNode.LinkCount);

                var frontLink = rightNode.FirstLink;
                while (frontLink != null)
                {
                    front.Add(frontLink);
                    frontPaths.Add(new GssLink <T> [fullSize]);

                    frontLink = frontLink.NextLink;
                }

                int k = size;
                while (0 != k--)
                {
                    int frontCount = front.Count;
                    for (int j = 0; j != frontCount; ++j)
                    {
                        var currLink = front[j];
                        frontPaths[j][k] = currLink;

                        if (k != 0)
                        {
                            front[j] = currLink.LeftNode.FirstLink;
                            var link = front[j].NextLink;

                            while (link != null)
                            {
                                front.Add(link);
                                var newPathLinks = (GssLink <T>[])frontPaths[j].Clone();
                                frontPaths.Add(newPathLinks);

                                link = link.NextLink;
                            }
                        }
                    }
                }

                int count = front.Count;
                for (int i = 0; i != count; ++i)
                {
                    action(new GssReducePath <T>(front[i].LeftNode, frontPaths[i], rule, fullSize));
                }
            }
        }