コード例 #1
0
        public void Analyze()
        {
            Item firstItem = new Item()
            {
                Rule         = grammer.GrammerRuleSet[0],
                DotPosition  = 0,
                IsCore       = true,
                FowardSearch = new List <VertexTerminator>()
                {
                    VertexTerminator.End
                }
            };
            ItemSet firstItemSet = new ItemSet();

            firstItemSet.AddItem(firstItem);

            ItemFamily itemFamily = new ItemFamily(grammer);

            itemFamily.FirstItemSet = firstItemSet;
            itemFamily.Register(firstItemSet);


            Queue <ItemSet> queue = new Queue <ItemSet>();

            queue.Enqueue(firstItemSet);


            int maxIndex = 0;

            while (queue.Count > 0)
            {
                ItemSet currentItemSet = queue.Dequeue();

                foreach (var actionItem in currentItemSet.ActionTable)
                {
                    var v      = actionItem.Key;
                    var action = actionItem.Value;
                    if (action.GetType() == typeof(GotoAction))
                    {
                        GotoAction gotoAction = (GotoAction)action;
                        if (gotoAction.ItemSet.Index > maxIndex)
                        {
                            queue.Enqueue(gotoAction.ItemSet);
                        }
                        maxIndex = Math.Max(maxIndex, gotoAction.ItemSet.Index);
                    }
                }
            }
            this.ItemFamily = itemFamily;
        }
コード例 #2
0
 public void SetFamily(ItemFamily family)
 {
     this.family = family;
 }