Ejemplo n.º 1
0
 public ParseTreeEnumerator(
     IInternalForestNode forestRoot)
 {
     _forestRoot = forestRoot;
     _status     = ParseTreeEnumeratorState.New;
     _visitor    = new ForestNodeVisitorImpl();
 }
Ejemplo n.º 2
0
 public ParseTreeEnumerator(
     IInternalForestNode forestRoot)
 {
     _forestRoot = forestRoot;
     _status = ParseTreeEnumeratorState.New;
     _visitor = new ForestNodeVisitorImpl();
 }
Ejemplo n.º 3
0
            private int GetOrSetChildIndex(IInternalForestNode symbolNode)
            {
                if (!_paths.TryGetValue(symbolNode, out int childIndex))
                {
                    _paths.Add(symbolNode, 0);
                    return(childIndex);
                }

                var isLocked = _lock is object;

                if (!isLocked)
                {
                    _lock = symbolNode;
                }

                var isCurrentNodeLocked = ReferenceEquals(_lock, symbolNode);

                if (!isCurrentNodeLocked)
                {
                    return(childIndex);
                }

                childIndex++;
                if (childIndex >= symbolNode.Children.Count)
                {
                    _lock = null;
                    _paths[symbolNode] = 0;
                    return(0);
                }
                _paths[symbolNode] = childIndex;
                return(childIndex);
            }
Ejemplo n.º 4
0
            private int GetOrSetChildIndex(IInternalForestNode symbolNode)
            {
                if (!this.paths.TryGetValue(symbolNode, out var childIndex))
                {
                    this.paths.Add(symbolNode, 0);
                    return(0);
                }

                var isLocked = !ReferenceEquals(null, this._lock);

                if (!isLocked)
                {
                    this._lock = symbolNode;
                }

                var isCurrentNodeLocked = ReferenceEquals(this._lock, symbolNode);

                if (!isCurrentNodeLocked)
                {
                    return(childIndex);
                }

                childIndex++;
                if (childIndex >= symbolNode.Children.Count)
                {
                    this._lock             = null;
                    this.paths[symbolNode] = 0;
                    return(0);
                }

                this.paths[symbolNode] = childIndex;
                return(childIndex);
            }
Ejemplo n.º 5
0
 public void Reset()
 {
     _paths.Clear();
     _nodeStack.Clear();
     _visited.Clear();
     _count = 0;
     _lock  = null;
 }
Ejemplo n.º 6
0
        private IForestNode CreateParseNode(
            IState nextState,
            IForestNode w,
            IForestNode v,
            int location)
        {
            Assert.IsNotNull(v, nameof(v));
            var anyPreDotRuleNull = true;

            if (nextState.DottedRule.Position > 1)
            {
                var predotPrecursorSymbol = nextState
                                            .DottedRule
                                            .Production
                                            .RightHandSide[nextState.DottedRule.Position - 2];
                anyPreDotRuleNull = IsSymbolNullable(predotPrecursorSymbol);
            }
            var anyPostDotRuleNull = IsSymbolNullable(nextState.PostDotSymbol);

            if (anyPreDotRuleNull && !anyPostDotRuleNull)
            {
                return(v);
            }

            IInternalForestNode internalNode = null;

            if (anyPostDotRuleNull)
            {
                internalNode = _nodeSet
                               .AddOrGetExistingSymbolNode(
                    nextState.DottedRule.Production.LeftHandSide,
                    nextState.Origin,
                    location);
            }
            else
            {
                internalNode = _nodeSet
                               .AddOrGetExistingIntermediateNode(
                    nextState,
                    nextState.Origin,
                    location
                    );
            }

            // if w = null and y doesn't have a family of children (v)
            if (w == null)
            {
                internalNode.AddUniqueFamily(v);
            }

            // if w != null and y doesn't have a family of children (w, v)
            else
            {
                internalNode.AddUniqueFamily(w, v);
            }

            return(internalNode);
        }
Ejemplo n.º 7
0
 public InternalTreeNode(
     IInternalForestNode internalNode,
     IForestDisambiguationAlgorithm stateManager)
 {
     _disambiguationAlgorithm = stateManager;
     _internalNode            = internalNode;
     _children = new List <ITreeNode>();
     SetSymbol(_internalNode);
 }
Ejemplo n.º 8
0
 public InternalTreeNode(
     IInternalForestNode internalNode,
     IForestDisambiguationAlgorithm stateManager)
 {
     _disambiguationAlgorithm = stateManager;
     _internalNode = internalNode;
     _children = new ReadWriteList<ITreeNode>();
     SetSymbol(_internalNode);
 }
Ejemplo n.º 9
0
        private static T GetAndCastChildAtIndex <T>(IInternalForestNode node, int index)
            where T : class, IForestNode
        {
            var firstAndNode = node.Children[0];

            Assert.IsNotNull(firstAndNode);
            Assert.IsFalse(index > firstAndNode.Children.Count);
            var child = firstAndNode.Children[index] as T;

            Assert.IsNotNull(child);
            return(child);
        }
Ejemplo n.º 10
0
        private void SetSymbol(IInternalForestNode node)
        {
            switch (node.NodeType)
            {
            case Forest.ForestNodeType.Symbol:
                Symbol = (node as ISymbolForestNode).Symbol as INonTerminal;
                break;

            case Forest.ForestNodeType.Intermediate:
                Symbol = (node as IIntermediateForestNode).State.DottedRule.Production.LeftHandSide;
                break;
            }
        }
Ejemplo n.º 11
0
        private void SetSymbol(IInternalForestNode node)
        {
            switch (node)
            {
            case ISymbolForestNode symbol:
                Symbol = symbol.Symbol as NonTerminal;
                break;

            case IIntermediateForestNode intermediate:
                Symbol = intermediate.DottedRule.Production.LeftHandSide;
                break;
            }
        }
Ejemplo n.º 12
0
 private void CloneUniqueChildSubTree(IInternalForestNode internalCompletedParseNode)
 {
     for (var a = 0; a < internalCompletedParseNode.Children.Count; a++)
     {
         var andNode    = internalCompletedParseNode.Children[a];
         var newAndNode = new AndForestNode();
         for (var c = 0; c < andNode.Children.Count; c++)
         {
             var child = andNode.Children[c];
             newAndNode.AddChild(child);
         }
         _children.Add(newAndNode);
     }
 }
Ejemplo n.º 13
0
        bool AreChildNodesEqual(IInternalForestNode firstInternalForestNode, IInternalForestNode secondInternalForestNode)
        {
            if (firstInternalForestNode.Children.Count != secondInternalForestNode.Children.Count)
            {
                return(false);
            }

            for (int i = 0; i < firstInternalForestNode.Children.Count; i++)
            {
                if (!AreAndNodesEqual(
                        firstInternalForestNode.Children[i],
                        secondInternalForestNode.Children[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 14
0
 public ParseTreeEnumerable(IInternalForestNode internalForestNode)
 {
     this._internalForestNode = internalForestNode;
 }
Ejemplo n.º 15
0
 public InternalTreeNode(
     IInternalForestNode internalNode)
     : this(internalNode, new SelectFirstChildDisambiguationAlgorithm())
 {
 }
Ejemplo n.º 16
0
 public InternalTreeNode(
     IInternalForestNode internalNode)
     : this(internalNode, new SelectFirstChildDisambiguationAlgorithm())
 {
 }
 public IAndForestNode GetCurrentAndNode(IInternalForestNode internalNode)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 18
0
 public void Dispose()
 {
     _visitor = null;
     _forestRoot = null;
 }
Ejemplo n.º 19
0
 public void Reset()
 {
     _paths.Clear();
     _nodeStack.Clear();
     _visited.Clear();
     _count = 0;
     _lock = null;
 }
Ejemplo n.º 20
0
            private int GetOrSetChildIndex(IInternalForestNode symbolNode)
            {
                var childIndex = 0;
                if (!_paths.TryGetValue(symbolNode, out childIndex))
                {
                    _paths.Add(symbolNode, 0);
                    return childIndex;
                }

                var isLocked = !object.ReferenceEquals(null, _lock);
                if (!isLocked)
                    _lock = symbolNode;

                var isCurrentNodeLocked = object.ReferenceEquals(_lock, symbolNode);
                if(!isCurrentNodeLocked)
                    return childIndex;

                childIndex++;
                if (childIndex >= symbolNode.Children.Count)
                {
                    _lock = null;
                    _paths[symbolNode] = 0;
                    return 0;
                }
                _paths[symbolNode] = childIndex;
                return childIndex;
            }
Ejemplo n.º 21
0
 public void Dispose()
 {
     _visitor    = null;
     _forestRoot = null;
 }
Ejemplo n.º 22
0
 private void CloneUniqueChildSubTree(IInternalForestNode internalCompletedParseNode)
 {
     for (var a = 0; a < internalCompletedParseNode.Children.Count; a++)
     {
         var andNode = internalCompletedParseNode.Children[a];
         var newAndNode = new AndForestNode();
         for (var c = 0; c < andNode.Children.Count; c++)
         {
             var child = andNode.Children[c];
             newAndNode.AddChild(child);
         }
         _children.Add(newAndNode);
     }
 }
 public IAndForestNode GetCurrentAndNode(IInternalForestNode internalNode)
 {
     return internalNode.Children[0];
 }
Ejemplo n.º 24
0
 public AndForestNode GetCurrentAndNode(IInternalForestNode internalNode)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 25
0
 public IAndForestNode GetCurrentAndNode(IInternalForestNode internalNode)
 {
     return(internalNode.Children[0]);
 }
Ejemplo n.º 26
0
        private void SetSymbol(IInternalForestNode node)
        {
            switch (node.NodeType)
            {
                case Forest.ForestNodeType.Symbol:
                    Symbol = (node as ISymbolForestNode).Symbol as INonTerminal;
                    break;

                case Forest.ForestNodeType.Intermediate:
                    Symbol = (node as IIntermediateForestNode).State.Production.LeftHandSide;
                    break;
            }
        }