示例#1
0
        /// <summary>
        /// 7 &lt;VOpt&gt; ::= &lt;V&gt; &lt;VOpt&gt;;
        /// <para>8 &lt;VOpt&gt; ::= "|" &lt;V&gt; &lt;VOpt&gt;;</para>
        /// <para>9 &lt;VOpt ::= null;</para>
        /// </summary>
        /// <param name="vlist"></param>
        /// <param name="candidate"></param>
        /// <param name="syntaxTree"></param>
        private static object GetGrammarVOpt(RightSection vlist,
                                             ProductionNodeList candidate, SyntaxTree <EnumTokenTypeCG, EnumVTypeCG, TreeNodeValueCG> syntaxTree)
        {//<VOpt> ::= <V> <VOpt> | "|" <V> <VOpt> | null; // 7 8 9
            if (syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_VOpt___tail_nullLeave() ||
                syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_VOpt___tail_identifierLeave() ||
                syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_VOpt___tail_numberLeave() ||
                syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_VOpt___tail_constStringLeave() ||
                syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_VOpt___constStringLeave() ||
                syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_VOpt___tail_lessThan_Leave()
                )
            {
                var v = GetGrammarV(syntaxTree.Children[0]);
                candidate.Add(v);

                return(GetGrammarVOpt(vlist, candidate, syntaxTree.Children[1]));
            }
            else if (syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_VOpt___tail_or_Leave())
            {
                ProductionNodeList newCandidate = new ProductionNodeList();
                vlist.Add(newCandidate);

                var v = GetGrammarV(syntaxTree.Children[1]);
                newCandidate.Add(v);

                return(GetGrammarVOpt(vlist, newCandidate, syntaxTree.Children[2]));
            }
            else if (syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_VOpt___tail_semicolon_Leave())
            {
                return(GetGrammarnull(syntaxTree.Children[0]));
            }
            else
            {
                return(string.Format("{0}", syntaxTree.CandidateFunc.ToString()));
            }
        }
示例#2
0
        /// <summary>
        /// 获取此产生式列表的列表(产生式右部)的复制品
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            var result = new RightSection();

            foreach (var element in this)
            {
                result.Add(element.Clone() as ProductionNodeList);
            }
            return(result);
        }
        /// <summary>
        /// From
        /// </summary>
        /// <param name="xContextfreeProduction"></param>
        /// <returns></returns>
        public static ContextfreeProduction From(XElement xContextfreeProduction)
        {
            if (xContextfreeProduction == null)
            {
                return(null);
            }
            if (xContextfreeProduction.Name != strContextfreeProduction)
            {
                return(null);
            }
            var result = new ContextfreeProduction();

            result.Left            = ProductionNode.From(xContextfreeProduction.Element(ProductionNode.strProductionNode));
            result.RightCollection = RightSection.From(xContextfreeProduction.Element(RightSection.strRightSection));
            return(result);
        }
示例#4
0
        /// <summary>
        /// From
        /// </summary>
        /// <param name="xProductionNodeListList"></param>
        /// <returns></returns>
        public static RightSection From(XElement xProductionNodeListList)
        {
            if (xProductionNodeListList == null)
            {
                return(null);
            }
            if (xProductionNodeListList.Name != strRightSection)
            {
                return(null);
            }
            var result = new RightSection();

            result.AddRange(
                from item in xProductionNodeListList.Elements(ProductionNodeList.strCandidate)
                select ProductionNodeList.From(item)
                );
            return(result);
        }
示例#5
0
        /// <summary>
        /// 4 &lt;VList&gt; ::= &lt;V&gt; &lt;VOpt&gt;;
        /// </summary>
        /// <param name="syntaxTree"></param>
        private static RightSection GetGrammarVList(SyntaxTree <EnumTokenTypeCG, EnumVTypeCG, TreeNodeValueCG> syntaxTree)
        {//<VList> ::= <V> <VOpt>; 4
            RightSection vlist = new RightSection();

            if (syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_VList___constStringLeave() ||
                syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_VList___tail_constStringLeave() ||
                syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_VList___tail_identifierLeave() ||
                syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_VList___tail_lessThan_Leave() ||
                syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_VList___tail_nullLeave() ||
                syntaxTree.CandidateFunc == LL1SyntaxParserCG.GetFuncParsecase_VList___tail_numberLeave())
            {
                var candidate = new ProductionNodeList();
                vlist.Add(candidate);

                var v = GetGrammarV(syntaxTree.Children[0]);
                candidate.Add(v);

                var info = GetGrammarVOpt(vlist, candidate, syntaxTree.Children[1]);
            }

            return(vlist);
        }