view Implab/Automaton/RegularExpressions/RegularDFADefinition.cs @ 169:54270c2f29f2 ref20160224

DFA refactoring
author cin
date Thu, 03 Mar 2016 08:41:02 +0300
parents e227e78d72e4
children 181119ef3b39
line wrap: on
line source

using System;

namespace Implab.Automaton.RegularExpressions {
    public class RegularDFADefinition<TInput, TTag> : DFATable {

        readonly IAlphabet<TInput> m_alphabet;

        public RegularDFADefinition(IAlphabet<TInput> alphabet) {
            Safe.ArgumentNotNull(alphabet, "aplhabet");

            m_alphabet = alphabet;
        }


        public IAlphabet<TInput> InputAlphabet {
            get {
                return m_alphabet;
            }
        }

        protected override DFAStateDescriptior[] ConstructTransitionTable() {
            if (InputAlphabet.Count != m_alphabet.Count)
                throw new InvalidOperationException("The alphabet doesn't match the transition table");
            
            return base.ConstructTransitionTable();
        }

        /// <summary>
        /// Optimize the specified alphabet.
        /// </summary>
        /// <param name = "dfaTable"></param>
        /// <param name="alphabet">Пустой алфавит, который будет зполнен в процессе оптимизации.</param>
        public void Optimize(IDFATableBuilder<TTag> dfaTable, IAlphabetBuilder<TInput> alphabet) {
            Safe.ArgumentNotNull(alphabet, "alphabet");
            Safe.ArgumentNotNull(dfaTable, "dfaTable");

            Optimize(dfaTable, InputAlphabet, alphabet, new DummyAlphabet(StateCount), new MapAlphabet<int>()); 
        }


    }
}