示例#1
0
        private IForestNode CreateNullParseNode(NonTerminal symbol, int location)
        {
            var symbolNode = NodeSet.AddOrGetExistingSymbolNode(symbol, location, location);
            var nullNode   = new SymbolForestNode(symbol, location, location); //new EpsilonForestNode(location);

            symbolNode.AddUniqueFamily(nullNode);
            return(symbolNode);
        }
示例#2
0
        private IForestNode CreateParseNode(
            DottedRule nextDottedRule,
            int origin,
            IForestNode w,
            IForestNode v,
            int location)
        {
            Assert.IsNotNull(v, nameof(v));
            var anyPreDotRuleNull = true;

            if (nextDottedRule.Dot > 1)
            {
                var preDotPrecursorSymbol = nextDottedRule.Production[nextDottedRule.Dot - 2];
                anyPreDotRuleNull = IsSymbolTransitiveNullable(preDotPrecursorSymbol);
            }

            var anyPostDotRuleNull = IsSymbolTransitiveNullable(nextDottedRule.PostDotSymbol);

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

            IInternalForestNode internalNode;

            if (anyPostDotRuleNull)
            {
                internalNode = NodeSet.AddOrGetExistingSymbolNode(nextDottedRule.Production.LeftHandSide, origin, location);
            }
            else
            {
                internalNode = NodeSet.AddOrGetExistingIntermediateNode(nextDottedRule, 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(v, w);
            }

            return(internalNode);
        }