/// <summary>
        /// 获取此上下文无关产生式列表的复制品
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            var result = new ContextfreeProductionList();

            result.AddRange(
                from item in this
                select(item.Clone() as ContextfreeProduction));
            return(result);
        }
        /// <summary>
        /// From
        /// </summary>
        /// <param name="xContextfreeProductionList"></param>
        /// <returns></returns>
        public static ContextfreeProductionList From(XElement xContextfreeProductionList)
        {
            if (xContextfreeProductionList == null)
            {
                return(null);
            }
            if (xContextfreeProductionList.Name != strContextfreeProductionList)
            {
                return(null);
            }
            var result = new ContextfreeProductionList();

            result.AddRange(
                from item in xContextfreeProductionList.Elements(ContextfreeProduction.strContextfreeProduction)
                select ContextfreeProduction.From(item)
                );
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// 从<code>XElement</code>中读取一个<code>ContextfreeGrammar</code>对象
        /// </summary>
        /// <param name="xContextfreeGrammar"></param>
        /// <returns></returns>
        public static ContextfreeGrammar From(XElement xContextfreeGrammar)
        {
            if (xContextfreeGrammar == null)
            {
                return(null);
            }
            if (xContextfreeGrammar.Name != strContextfreeGrammar)
            {
                return(null);
            }
            var result = new ContextfreeGrammar();

            result.GrammarName          = xContextfreeGrammar.Attribute(strGrammarName).Value;
            result.Namespace            = xContextfreeGrammar.Attribute(strNamespace).Value;
            result.ProductionCollection = ContextfreeProductionList.From(
                xContextfreeGrammar.Element(ContextfreeProductionList.strContextfreeProductionList));
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// 2 &lt;PList&gt; ::= &lt;Vn&gt; "::=" &lt;VList&gt; ";" &lt;PList&gt;;
        /// <para>3 &lt;PList&gt; ::= null;</para>
        /// </summary>
        /// <param name="plist"></param>
        /// <param name="syntaxTree"></param>
        private static void GetGrammarPList(
            ContextfreeProductionList plist, SyntaxTree <EnumTokenTypeCG, EnumVTypeCG, TreeNodeValueCG> syntaxTree)
        {//<PList> ::= <Vn> "::=" <VList> ";" <PList> | null; 2 3
            if (syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_PList___tail_lessThan_Leave())
            {
                ContextfreeProduction production = new ContextfreeProduction();
                plist.Add(production);

                var vn = GetGrammarVn(syntaxTree.Children[0]);
                production.Left = vn;

                var vlist = GetGrammarVList(syntaxTree.Children[2]);
                production.RightCollection = vlist;

                GetGrammarPList(plist, syntaxTree.Children[4]);
            }
            else if (syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_PList___tail_startEndLeave())
            {
                // nothing to do
                //GetGrammarnull(syntaxTree.Children[0]);
            }
        }