Пример #1
0
        static internal RegexAutomaton Create(CharSetSolver solver, Regex regex)
        {
            int t0       = System.Environment.TickCount;
            var nfa      = solver.Convert(regex.ToString(), regex.Options);
            var minterms = GetMinterms(nfa);
            //create specialized BV algebra for this particular minterm partition
            var bvsolver = new BVAlgebra(solver, minterms);
            //convert the nfa to the specialized algebra
            var nfa_BV = nfa.ReplaceAlgebra <BV>(bvsolver.MapPredToBV, bvsolver);

            t0 = System.Environment.TickCount - t0;
            int t    = System.Environment.TickCount;
            var nfa1 = nfa.Minimize();//.RemoveEpsilons().Minimize();
            var dfa  = nfa1.Determinize().Minimize().Normalize();

            t = System.Environment.TickCount - t;
            int t_BV       = System.Environment.TickCount;
            var nfa1_BV    = nfa_BV;//.RemoveEpsilons().Minimize();
            var dfa_BV     = nfa1_BV.Minimize().Determinize();
            var dfa_BV_min = dfa_BV.Minimize().Normalize();

            t_BV = System.Environment.TickCount - t_BV;
            //number of states
            var N = dfa.StateCount;
            //number of symbols
            int t2                = System.Environment.TickCount;
            var K                 = minterms.Length;
            var isfinalstate      = new HashSet <int>();
            var nonfinalSinkstate = -1;
            var finalSinkstate    = -1;

            for (int q = 0; q < N; q++)
            {
                if (dfa.IsFinalState(q))
                {
                    isfinalstate.Add(q);
                }
                if (dfa.IsLoopState(q) && dfa.GetMovesCountFrom(q) == 1)
                {
                    //there can only be at most one of each because dfa is minimal
                    if (dfa.IsFinalState(q))
                    {
                        if (finalSinkstate != -1)
                        {
                            throw new AutomataException(AutomataExceptionKind.InternalError_RegexAutomaton);
                        }
                        finalSinkstate = q;
                    }
                    else
                    {
                        if (nonfinalSinkstate != -1)
                        {
                            throw new AutomataException(AutomataExceptionKind.InternalError_RegexAutomaton);
                        }
                        nonfinalSinkstate = q;
                    }
                }
            }
            var delta = new int[K * N];

            for (int q = 0; q < dfa.StateCount; q++)
            {
                int symbols_mapped = 0;
                foreach (var move in dfa.GetMovesFrom(q))
                {
                    for (int a = 0; a < K; a++)
                    {
                        var phi = solver.MkAnd(move.Label, minterms[a]);
                        if (!phi.IsEmpty)
                        {
                            delta[(move.SourceState * K) + a] = move.TargetState;
                            symbols_mapped += 1;
                        }
                    }
                }
                if (symbols_mapped != K)
                {
                    throw new AutomataException(AutomataExceptionKind.InternalError_RegexAutomaton);
                }
            }
            var dt = DecisionTree.Create(solver, minterms);
            var ra = new RegexAutomaton(bvsolver, regex, K, N, delta, isfinalstate, dt, nonfinalSinkstate, finalSinkstate);

            t2 = System.Environment.TickCount - t2;
            return(ra);
        }
Пример #2
0
 internal BVAlgebraBase(DecisionTree dtree, IntervalSet[] partition, int nrOfBits)
 {
     this.dtree     = dtree;
     this.partition = partition;
     this.nrOfBits  = nrOfBits;
 }
Пример #3
0
 internal RegexAutomaton(BVAlgebra algebra, Regex regex, int alphabetSize, int stateCount, int[] delta, HashSet <int> isfinalstate, DecisionTree dt, int nonfinalSinkState = -1, int finalSinkState = -1)
 {
     this.algebra           = algebra;
     this.regex             = regex;
     this.SymbolCount       = alphabetSize;
     this.StateCount        = stateCount;
     this.delta             = delta;
     this.finalstates       = isfinalstate;
     this.NonfinalSinkState = nonfinalSinkState;
     this.FinalSinkState    = finalSinkState;
     this.dt = dt;
 }