Example #1
0
        public SppfNode CreateBranch(
            Production prod,
            ArraySlice <SppfNode> parts,
            IStackLookback <SppfNode> stackLookback)
        {
            // Produce more dense tree
            if (parts.Count == 0)
            {
                return(GetDefault(prod.OutcomeToken, stackLookback));
            }

            SppfNode[] children = new SppfNode[prod.Pattern.Length];
            parts.CopyTo(children, 0);

            Loc location  = Loc.Unknown;
            int partCount = parts.Count;

            for (int i = 0; i != partCount; ++i)
            {
                location += children[i].Location;
            }

            if (prod.PatternTokens.Length > parts.Count)
            {
                FillEpsilonSuffix(prod.Index, parts.Count, children, parts.Count, stackLookback);
            }

            return(new SppfNode(prod.Index, location, children));
        }
Example #2
0
 public void FillEpsilonSuffix(
     int ruleId,
     int prefixSize,
     T[] buffer,
     int destIndex,
     IStackLookback <T> lookback)
 {
 }
Example #3
0
        public Msg Merge(Msg alt1, Msg alt2, IStackLookback <Msg> stackLookback)
        {
            var result = new Msg(
                alt1.Id,
                this.merge(alt1.Id, alt1.Value, alt2.Value, context, stackLookback),
                alt1.Location);

            return(result);
        }
 public void FillEpsilonSuffix(int prodId, int prefixSize, Msg[] buffer, int destIndex, IStackLookback<Msg> stackLookback)
 {
     var production = grammar.Productions[prodId];
     int i   = prefixSize;
     int end = production.PatternTokens.Length;
     while (i != end)
     {
         buffer[destIndex++] = GetDefault(production.PatternTokens[i++], stackLookback);
     }
 }
        public void FillEpsilonSuffix(int ruleId, int prefixSize, SppfNode[] dest, int destIndex, IStackLookback<SppfNode> stackLookback)
        {
            int i   = ruleOffsetInCache[ruleId] + prefixSize;
            int end = ruleEndOffsetInCache[ruleId];

            while (i != end)
            {
                dest[destIndex++] = ruleCache[i++];
            }
        }
Example #6
0
        public SppfNode Merge(SppfNode alt1, SppfNode alt2, IStackLookback <SppfNode> stackLookback)
        {
            var alt = alt1;

            do
            {
                if (alt2.EquivalentTo(alt))
                {
                    return(alt1);
                }

                alt = alt.NextAlternative;
            }while (alt != null);

            return(alt1.AddAlternative(alt2));
        }
Example #7
0
        public Msg CreateBranch(Production rule, ArraySlice <Msg> prefix, IStackLookback <Msg> stackLookback)
        {
            if (prefix.Count == 0)
            {
                return(GetDefault(rule.OutcomeToken, stackLookback));
            }

            Loc  location;
            HLoc hLocation;

            var array = prefix.Array;

            switch (prefix.Count)
            {
            case 0:
                location  = Loc.Unknown;
                hLocation = HLoc.Unknown;
                break;

            case 1:
                location  = prefix.Array[prefix.Offset].Location;
                hLocation = prefix.Array[prefix.Offset].HLocation;
                break;

            default:
                location = prefix.Array[prefix.Offset].Location
                           + prefix.Array[prefix.Offset + prefix.Count - 1].Location;
                hLocation = prefix.Array[prefix.Offset].HLocation
                            + prefix.Array[prefix.Offset + prefix.Count - 1].HLocation;
                break;
            }

            // Location for IParsing service
            this._resultLocation  = location;
            this._resultHLocation = hLocation;

            if (rule.PatternTokens.Length > prefix.Count)
            {
                FillEpsilonSuffix(rule.Index, prefix.Count, prefix.Array, prefix.Offset + prefix.Count, stackLookback);
            }

            object value = grammarAction(rule.Index, prefix.Array, prefix.Offset, context, stackLookback);

            return(new Msg(rule.OutcomeToken, value, location, hLocation));
        }
        private Msg InternalGetNullable(int nonTerm, IStackLookback<Msg> stackLookback)
        {
            Debug.Assert(grammar.IsNullable(nonTerm));

            var production =
                      (from r in grammar.GetProductions(nonTerm)
                       where r.PatternTokens.All(grammar.IsNullable)
                       orderby r.PatternTokens.Length ascending
                       select r)
                       .First();

            var args = new Msg[production.PatternTokens.Length];
            for (int i = 0; i != args.Length; ++i)
            {
                args[i] = InternalGetNullable(production.PatternTokens[i], stackLookback);
            }

            var value = productionAction(production.Index, args, 0, context, stackLookback);
            return new Msg(nonTerm, value, Loc.Unknown);
        }
Example #9
0
        private object DefaultMerge(
            int                 token,
            object              alt1,
            object              alt2,
            object              context,
            IStackLookback<Msg> stackLookback)
        {
            var result = alt2;
#if true
            Debug.WriteLine("------------------------------");
            Debug.WriteLine(
                "Default merging of token {0} values in state {1}:",
                (object)runtimeGrammar.SymbolName(token),
                stackLookback.GetParentState());
            Debug.WriteLine("  '{0}'", alt1);
            Debug.WriteLine(" and");
            Debug.WriteLine("  '{0}'", alt2);
            Debug.WriteLine(" into the value: '{0}'", (object)result);
#endif
            return result;
        }
        private Msg InternalGetNullable(int nonTerm, IStackLookback <Msg> stackLookback)
        {
            Debug.Assert(grammar.IsNullable(nonTerm));

            var production =
                (from r in grammar.GetProductions(nonTerm)
                 where r.PatternTokens.All(grammar.IsNullable)
                 orderby r.PatternTokens.Length ascending
                 select r)
                .First();

            var args = new Msg[production.PatternTokens.Length];

            for (int i = 0; i != args.Length; ++i)
            {
                args[i] = InternalGetNullable(production.PatternTokens[i], stackLookback);
            }

            var value = productionAction(production.Index, args, 0, context, stackLookback);

            return(new Msg(nonTerm, value, Loc.Unknown));
        }
 public Msg GetDefault(int nonTerm, IStackLookback<Msg> stackLookback)
 {
     Msg result = InternalGetNullable(nonTerm, stackLookback);
     return result;
 }
Example #12
0
 public T CreateBranch(Production rule, Algorithm.ArraySlice <T> parts, IStackLookback <T> lookback)
 {
     return(default(T));
 }
Example #13
0
 public T Merge(T alt1, T alt2, IStackLookback <T> lookback)
 {
     return(default(T));
 }
        public void FillEpsilonSuffix(int prodId, int prefixSize, Msg[] buffer, int destIndex, IStackLookback <Msg> stackLookback)
        {
            var production = grammar.Productions[prodId];
            int i          = prefixSize;
            int end        = production.PatternTokens.Length;

            while (i != end)
            {
                buffer[destIndex++] = GetDefault(production.PatternTokens[i++], stackLookback);
            }
        }
        public Msg GetDefault(int nonTerm, IStackLookback <Msg> stackLookback)
        {
            Msg result = InternalGetNullable(nonTerm, stackLookback);

            return(result);
        }
 public SppfNode GetDefault(int nonTerm, IStackLookback<SppfNode> stackLookback)
 {
     return tokenCache[nonTerm];
 }
Example #17
0
 public T GetDefault(int nonTerm, IStackLookback <T> lookback)
 {
     return(default(T));
 }
 public SppfNode GetDefault(int nonTerm, IStackLookback <SppfNode> stackLookback)
 {
     return(tokenCache[nonTerm]);
 }
        public void FillEpsilonSuffix(int ruleId, int prefixSize, SppfNode[] dest, int destIndex, IStackLookback <SppfNode> stackLookback)
        {
            int i   = ruleOffsetInCache[ruleId] + prefixSize;
            int end = ruleEndOffsetInCache[ruleId];

            while (i != end)
            {
                dest[destIndex++] = ruleCache[i++];
            }
        }