private static RightPartList GetRightPartList(SyntaxTree syntaxTree) { RightPartList result = null; // <RightPartList> ::= "|" <Canditate> <RightPartList> | null ; if (syntaxTree.NodeType.Type == ContextfreeGrammarTreeNodeType.__RightPartList) { if (syntaxTree.Children.Count == 3) { // <RightPartList> ::= "|" <Canditate> <RightPartList> ; Candidate candidate = GetCandidate(syntaxTree.Children[1]); result = new RightPartList(); result.Add(candidate); RightPartList list = GetRightPartList(syntaxTree.Children[2]); result.AddRange(list); } else if (syntaxTree.Children.Count == 0) { // <RightPartList> ::= null ; result = new RightPartList(); } } return(result); }
private static List <Regulation> GetProduction(SyntaxTree syntaxTree) { // <Production> ::= <Vn> "::=" <Canditate> <RightPartList> ; List <Regulation> result = new List <Regulation>(); if (syntaxTree.NodeType.Type == ContextfreeGrammarTreeNodeType.__Production) { Vn left = GetVn(syntaxTree.Children[0]); TreeNodeType leftNode = left.GetTreeNodeType(); { Candidate candidate = GetCandidate(syntaxTree.Children[2]); var regulation = new Regulation(leftNode, (from item in candidate select item.GetTreeNodeType()).ToArray()); result.Add(regulation); } RightPartList rightPartList = GetRightPartList(syntaxTree.Children[3]); foreach (var candidate in rightPartList) { var regulation = new Regulation(leftNode, (from item in candidate select item.GetTreeNodeType()).ToArray()); result.Add(regulation); } } return(result); }