예제 #1
0
        public IDfaSet Read()
        {
            var map = this.reader.ReadInt32Array();

            var setsCount = this.reader.ReadInt32();
            var sets      = new Set[setsCount];

            for (var s = 0; s < sets.Length; ++s)
            {
                var intervalCount = this.reader.ReadInt32();
                var intervals     = new Interval[intervalCount];
                for (var i = 0; i < intervalCount; ++i)
                {
                    var min = this.reader.ReadInt32();
                    var max = this.reader.ReadInt32();
                    intervals[i] = new Interval(min, max);
                }
                sets[s] = new Set(intervals);
            }

            var dfaCount = this.reader.ReadInt32();
            var dfas     = new Dfa[dfaCount];

            for (var d = 0; d < dfaCount; ++d)
            {
                var stateCount = this.reader.ReadInt32();
                var states     = new DfaState[stateCount];
                for (var s = 0; s < stateCount; ++s)
                {
                    var final   = this.reader.ReadBool();
                    var payload = this.reader.ReadInt32() - 1;
                    states[s] = new DfaState(s, final, payload);
                }
                for (var s = 0; s < stateCount; ++s)
                {
                    var transitionCount = this.reader.ReadInt32();
                    var transitions     = new DfaTrans[transitionCount];
                    for (var t = 0; t < transitionCount; ++t)
                    {
                        var setId    = this.reader.ReadInt32();
                        var targetId = this.reader.ReadInt32();
                        Debug.Assert(targetId < stateCount);
                        transitions[t] = new DfaTrans(states[targetId], sets[setId]);
                    }
                    states[s].Transitions = transitions;
                }
                dfas[d] = new Dfa(states);
            }

            return(new DfaSet(dfas, map, dfas.Last()));
        }
예제 #2
0
        public Dfa Read()
        {
            var stateCount = ReadInt32();
            var states     = new DfaState[stateCount];

            for (var i = 0; i < stateCount; ++i)
            {
                var final   = ReadBool();
                var payload = ReadInt32() - 1;
                var trans   = new DfaTrans[ReadInt32()];
                states[i] = new DfaState(i, final, payload, trans);
            }

            var setCount = ReadInt32();
            var sets     = new Set[setCount];

            for (var s = 0; s < setCount; ++s)
            {
                var intervalCount = ReadInt32();
                var intervals     = new Interval[intervalCount];
                for (var i = 0; i < intervalCount; ++i)
                {
                    intervals[i] = new Interval(ReadInt32(), ReadInt32());
                }
                sets[s] = new Set(intervals);
            }

            var transitionCount = ReadInt32();
            var transitions     = new DfaTrans[transitionCount];

            for (var t = 0; t < transitionCount; ++t)
            {
                var target = states[ReadInt32()];
                var set    = sets[ReadInt32()];
                transitions[t] = new DfaTrans(target, set);
            }

            for (var s = 0; s < stateCount; ++s)
            {
                var state = states[s];
                for (var t = 0; t < state.Transitions.Length; ++t)
                {
                    state.Transitions[t] = transitions[ReadInt32()];
                }
            }

            return(new Dfa(states));
        }