Ejemplo n.º 1
0
        private SelectClauseNode(int letter, LetterRecursionType recursion, IEnumerable<ISelectClauseNode> children)
        {
            Letter = letter;
            Recursive = recursion;
            Children = children != null ? children.ToList() : new List<ISelectClauseNode>();

            foreach (var c in Children)
            {
                c.Parent = this;
            }

            Parent = null;
        }
Ejemplo n.º 2
0
        private SelectClauseNode(int letter, LetterRecursionType recursion, IEnumerable <ISelectClauseNode> children)
        {
            Letter    = letter;
            Recursive = recursion;
            Children  = children != null?children.ToList() : new List <ISelectClauseNode>();

            foreach (var c in Children)
            {
                c.Parent = this;
            }

            Parent = null;
        }
Ejemplo n.º 3
0
        public static SelectIntruction PrepareInstructions(ISelectClauseNode parseRoot)
        {
            var res = new SelectIntruction {
                ArrayLength = parseRoot.GetList().Select(z => z.Letter).Max() + 1
            };

            foreach (var e in parseRoot.GetList())
            {
                var ins = new LetterInstruction {
                    LetterIndex = e.Letter, IsRoot = e.Parent == null
                };
                if (!ins.IsRoot)
                {
                    ins.ParentIndex        = e.Parent.Letter;
                    ins.ChildNumberInArray = e.Parent.Children.IndexOf(e);
                    ins.LeftBrotherIndexes = e.Parent.Children.Take(ins.ChildNumberInArray).Select(z => z.Letter).ToArray();
                }
                else
                {
                    ins.LeftBrotherIndexes = new int[] { };
                }

                if (e.Children.Count != 0)
                {
                    if (e.Children.Count != 0)
                    {
                        var sub   = Math.Sign(e.Children.Count(z => z.Recursive == LetterRecursionType.Subtree));
                        var child = Math.Sign(e.Children.Count(z => z.Recursive == LetterRecursionType.Children));
                        var clear = Math.Sign(e.Children.Count(z => z.Recursive == LetterRecursionType.No));
                        if (sub + child + clear > 1)
                        {
                            throw new Exception("Error in rule: letter " + (char)('A' + e.Letter) + " must have only one type of childs (for example A(?B,.C) is not acceptable)");
                        }
                        if (clear != 0)
                        {
                            ins.Arity = e.Children.Count;
                        }
                    }
                }

                ins.Recursive = e.Recursive;
                res.Letters.Add(ins);
            }
            return(res);
        }
Ejemplo n.º 4
0
        public static SelectIntruction PrepareInstructions(ISelectClauseNode parseRoot)
        {
            var res = new SelectIntruction {ArrayLength = parseRoot.GetList().Select(z => z.Letter).Max() + 1};
            foreach (var e in parseRoot.GetList())
            {
                var ins = new LetterInstruction {LetterIndex = e.Letter, IsRoot = e.Parent == null};
                if (!ins.IsRoot)
                {
                   ins.ParentIndex = e.Parent.Letter;
                   ins.ChildNumberInArray = e.Parent.Children.IndexOf(e);
                   ins.LeftBrotherIndexes = e.Parent.Children.Take(ins.ChildNumberInArray).Select(z => z.Letter).ToArray();
                }
                else
                {
                    ins.LeftBrotherIndexes = new int[] { };
                }

                if (e.Children.Count != 0)
                {
                    if (e.Children.Count != 0)
                    {
                        var sub = Math.Sign(e.Children.Count(z => z.Recursive == LetterRecursionType.Subtree));
                        var child = Math.Sign(e.Children.Count(z => z.Recursive == LetterRecursionType.Children));
                        var clear = Math.Sign(e.Children.Count(z => z.Recursive == LetterRecursionType.No));
                        if (sub + child + clear > 1) throw new Exception("Error in rule: letter " + (char)('A' + e.Letter) + " must have only one type of childs (for example A(?B,.C) is not acceptable)");
                        if (clear != 0)
                            ins.Arity = e.Children.Count;
                    }

                }

                ins.Recursive = e.Recursive;
                res.Letters.Add(ins);
            }
            return res;
        }
Ejemplo n.º 5
0
 public BasicSelector(ISelectClauseNode clause)
 {
     _instruction = PrepareInstructions(clause);
 }
Ejemplo n.º 6
0
 public BasicSelector(ISelectClauseNode clause)
 {
     _instruction = PrepareInstructions(clause);
 }