Ejemplo n.º 1
0
        public static void GetFirstCollection(
            this RegulationList grammar,
            out FIRSTCollection firstCollection, Dictionary <TreeNodeType, bool> nullableDict = null)
        {
            if (nullableDict == null)
            {
                GetNullableDict(grammar, out nullableDict);
            }

            FIRSTCollection firstList4Node;

            grammar.GetFirstCollection4Node(out firstList4Node, nullableDict);
            FIRSTCollection firstList4Regulation;

            grammar.GetFirstCollection4Regulation(out firstList4Regulation,
                                                  nullableDict, firstList4Node);

            firstCollection = new FIRSTCollection();
            foreach (var item in firstList4Node)
            {
                firstCollection.TryInsert(item);
            }
            foreach (var item in firstList4Regulation)
            {
                firstCollection.TryInsert(item);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 计算文法的FIRST和FOLLOW集
        /// </summary>
        /// <param name="grammar"></param>
        /// <returns></returns>
        public static FirstListAndFollowList GetFirstListAndFollowList(this RegulationList grammar)
        {
            Dictionary <TreeNodeType, bool> nullableDict = new Dictionary <TreeNodeType, bool>();

            GetNullableDict(grammar, out nullableDict);
            FIRSTCollection firstCollection4Node;

            grammar.GetFirstCollection4Node(out firstCollection4Node, nullableDict);
            FIRSTCollection firstCollection4Regulation;

            grammar.GetFirstCollection4Regulation(out firstCollection4Regulation, nullableDict, firstCollection4Node);
            FOLLOWCollection followCollection;

            grammar.GetFollowCollection(out followCollection, nullableDict, firstCollection4Node);

            var firstCollection = new FIRSTCollection();

            foreach (var item in firstCollection4Node)
            {
                firstCollection.TryInsert(item);
            }
            foreach (var item in firstCollection4Regulation)
            {
                firstCollection.TryInsert(item);
            }
            return(new FirstListAndFollowList(firstCollection, followCollection));
        }
Ejemplo n.º 3
0
        public static void GetFollowCollection(
            this RegulationList grammar,
            out FOLLOWCollection followCollection,
            Dictionary <TreeNodeType, bool> nullableDict = null,
            FIRSTCollection firstCollection = null)
        {
            if (nullableDict == null)
            {
                grammar.GetNullableDict(out nullableDict);
            }
            if (firstCollection == null)
            {
                grammar.GetFirstCollection(out firstCollection, nullableDict);
            }

            FIRSTCollection firstList4Node;

            grammar.GetFirstCollection4Node(out firstList4Node, nullableDict);
            FIRSTCollection firstList4Regulation;

            grammar.GetFirstCollection4Regulation(out firstList4Regulation, nullableDict, firstList4Node);
            grammar.DoGetFollowList(out followCollection, nullableDict, firstList4Node);
        }