Exemplo n.º 1
0
 public VirtualForestNode(
     int location,
     ITransitionState transitionState,
     IForestNode completedParseNode)
     : this(location,
           transitionState, 
           completedParseNode,
           transitionState.GetTargetState())
 {
 }
Exemplo n.º 2
0
        protected VirtualForestNode(
            int location,
            ITransitionState transitionState,
            IForestNode completedParseNode,
            IState targetState)
            : base(targetState.Origin, location)
        {
            _paths = new List<VirtualForestNodePath>();

            Symbol = targetState.Production.LeftHandSide;
            _hashCode = ComputeHashCode();
            var path = new VirtualForestNodePath(transitionState, completedParseNode);
            AddUniquePath(path);
        }
Exemplo n.º 3
0
        private static bool IsMatchedSubTree(IForestNode firstChild, IForestNode secondChild, IAndForestNode andNode)
        {
            var firstCompareNode = andNode.Children[0];

            // if first child matches the compare node, continue
            // otherwise return false
            if (!firstChild.Equals(firstCompareNode))
                return false;

            if (secondChild == null)
                return true;

            var secondCompareNode = andNode.Children[1];

            // return true if the second child matches
            // otherwise return false
            return secondChild.Equals(secondCompareNode);
        }
Exemplo n.º 4
0
        private static bool IsMatchedSubTree(IForestNode firstChild, IForestNode secondChild, IAndForestNode andNode)
        {
            var firstCompareNode = andNode.Children[0];

            // if first child matches the compare node, continue
            // otherwise return false
            if (!firstChild.Equals(firstCompareNode))
            {
                return(false);
            }

            if (secondChild == null)
            {
                return(true);
            }

            var secondCompareNode = andNode.Children[1];

            // return true if the second child matches
            // otherwise return false
            return(secondChild.Equals(secondCompareNode));
        }
Exemplo n.º 5
0
        private void AddUniqueAndNode(IForestNode first, IForestNode second = null)
        {
            var childCount = 1 + (second == null ? 0 : 1);

            foreach (var andNode in this.children)
            {
                if (andNode.Children.Count != childCount)
                {
                    continue;
                }

                if (IsMatchedSubTree(andNode, first, second))
                {
                    return;
                }
            }

            // not found so add new and node
            var newAndNode = AndForestNode.Make(first, second);

            Debug.Assert(!(this is IntermediateForestNode) || this.children.Count == 0);
            this.children.Add(newAndNode);
        }
Exemplo n.º 6
0
        private void AddUniqueAndNode(IForestNode firstChild, IForestNode secondChild)
        {
            var childCount = 1 + ((secondChild == null) ? 0 : 1);

            for (var c = 0; c < _children.Count; c++)
            {
                var andNode = _children[c];

                if (andNode.Children.Count != childCount)
                    continue;

                if (IsMatchedSubTree(firstChild, secondChild, andNode))
                    return;
            }

            // not found so return new and node
            var newAndNode = new AndForestNode();
            newAndNode.AddChild(firstChild);
            if (childCount > 1)
                newAndNode.AddChild(secondChild);

            _children.Add(newAndNode);
        }
Exemplo n.º 7
0
 private static bool IsMatchedSubTree(AndForestNode andNode, IForestNode first, IForestNode second)
 {
     return(first.Equals(andNode.First) && (second == null || second.Equals(andNode.Second)));
 }
Exemplo n.º 8
0
 public void AddUniqueFamily(IForestNode trigger)
 {
     AddUniqueAndNode(trigger);
 }
Exemplo n.º 9
0
 public VirtualForestNodePath(ITransitionState transitionState, IForestNode forestNode)
 {
     TransitionState = transitionState;
     ForestNode = forestNode;
     _hashCode = ComputeHashCode(TransitionState, ForestNode);
 }
Exemplo n.º 10
0
 public void AddUniqueFamily(IForestNode trigger)
 {
     AddUniqueAndNode(trigger);
 }
Exemplo n.º 11
0
 public VirtualForestNodePath(ITransitionState transitionState, IForestNode forestNode)
 {
     TransitionState = transitionState;
     ForestNode      = forestNode;
     _hashCode       = ComputeHashCode(TransitionState, ForestNode);
 }
Exemplo n.º 12
0
 public void AddUniqueFamily(IForestNode source, IForestNode trigger)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 13
0
        static void AssertForestsAreEqual(IForestNode expected, IForestNode actual)
        {
            var comparer = new StatefulForestNodeComparer();

            Assert.IsTrue(comparer.Equals(expected, actual));
        }
Exemplo n.º 14
0
 public void Add(IForestNode child)
 {
     _children.Add(child);
 }
Exemplo n.º 15
0
 public void AddChild(IForestNode orNode)
 {
     _children.Add(orNode);
 }
Exemplo n.º 16
0
 public CompletedState(DottedRule dottedRule, int origin, IForestNode parseNode)
     : base(dottedRule, origin, parseNode)
 {
 }
Exemplo n.º 17
0
 public void SetParseNode(IForestNode parseNode)
 {
     ParseNode = parseNode;
 }
Exemplo n.º 18
0
        private IForestNode CreateParseNode(
            IState nextState,
            IForestNode w,
            IForestNode v,
            int location)
        {
            Assert.IsNotNull(v, nameof(v));
            var anyPreDotRuleNull = true;
            if (nextState.Position > 1)
            {
                var predotPrecursorSymbol = nextState
                    .Production
                    .RightHandSide[nextState.Position - 2];
                anyPreDotRuleNull = IsSymbolNullable(predotPrecursorSymbol);
            }
            var anyPostDotRuleNull = IsSymbolNullable(nextState.PostDotSymbol);
            if (anyPreDotRuleNull && !anyPostDotRuleNull)
                return v;

            IInternalForestNode internalNode = null;
            if (anyPostDotRuleNull)
            {
                internalNode = _nodeSet
                    .AddOrGetExistingSymbolNode(
                        nextState.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;
        }
Exemplo n.º 19
0
 public PredictionState(DottedRule dottedRule, int origin, IForestNode parseNode)
     : base(dottedRule, origin, parseNode)
 {
 }
Exemplo n.º 20
0
 private static int ComputeHashCode(ITransitionState transitionState, IForestNode forestNode)
 {
     return(HashCode.Compute(
                transitionState.GetHashCode(),
                forestNode.GetHashCode()));
 }
Exemplo n.º 21
0
 public void AddUniqueFamily(IForestNode source, IForestNode trigger)
 {
     if(source == this)
         source = Children[0].Children[0];
     AddUniqueAndNode(source, trigger);
 }
Exemplo n.º 22
0
 public IState NewState(IDottedRule dottedRule, int origin, IForestNode forestNode = null)
 {
     return(forestNode is null
         ? new NormalState(dottedRule, origin)
         : new NormalState(dottedRule, origin, forestNode));
 }
Exemplo n.º 23
0
 private void AddUniqueAndNode(IForestNode child)
 {
     AddUniqueAndNode(child, null);
 }
Exemplo n.º 24
0
 private void AddUniqueAndNode(IForestNode child)
 {
     AddUniqueAndNode(child, null);
 }
Exemplo n.º 25
0
 public NormalState(IDottedRule dottedRule, int origin, IForestNode parseNode)
     : this(dottedRule, origin)
 {
     ParseNode = parseNode;
 }
Exemplo n.º 26
0
 public void AddUniqueFamily(IForestNode source, IForestNode trigger)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 27
0
 public void AddChild(IForestNode orNode)
 {
     _children.Add(orNode);
 }
Exemplo n.º 28
0
 public void AddUniqueFamily(IForestNode trigger)
 {
     Debug.Assert(!(this is IntermediateForestNode) || Children.Count == 0);
     AddUniqueAndNode(trigger);
 }
Exemplo n.º 29
0
 private static int ComputeHashCode(ITransitionState transitionState, IForestNode forestNode)
 {
     return HashCode.Compute(
         transitionState.GetHashCode(),
         forestNode.GetHashCode());
 }
Exemplo n.º 30
0
 public void Add(IForestNode child)
 {
     _children.Add(child);
 }