public ail.net.parser.Fsa Minimize(ail.net.parser.Fsa.EMinimizationMode xi_mode) { ail.net.parser.Fsa result = new ail.net.parser.Fsa(); // phase I (clean) RemoveUselessStates(); // phase II (divide fsa into equivalent groups, each group will be new fsa state) Hashtable partition = new Hashtable(); BuildPartition(ref partition, xi_mode); // phase III (compose fsa) foreach (ail.net.parser.FsaStateSet group in partition.Values) { ail.net.parser.FsaState new_state = result.AddState(group.Id); ail.net.parser.FsaState old_state = (ail.net.parser.FsaState)ail.net.framework.Functor.FirstElementOfCollection(group.States.Values); // check if group has start state foreach (ail.net.parser.FsaState state in group.States.Values) { if (IsStartState(state)) { result.StartState = new_state; break; } } // check if group final state foreach (ail.net.parser.FsaState state in group.States.Values) { if (IsFinalState(state)) { result.AddFinalState(new_state, state.Token); break; } } // add transitions foreach (ail.net.parser.FsaTransition transition in old_state.Transitions.Values) { ail.net.parser.FsaStateSet transition_group = GetGroupFromState(transition.End, partition); ail.net.framework.Assert.NonNullReference(transition_group, "transition_group"); result.AddTransition(new_state.Id, transition_group.Id, transition.Predicate.Text, transition.Predicate.SwitchChar, transition.Predicate.Context, transition.Predicate.Rank); } } // phase IV (clean) result.RemoveUselessStates(); return(result); }
private void BuildPartition(ref Hashtable xio_partition, ail.net.parser.Fsa.EMinimizationMode xi_mode) { ail.net.framework.Assert.NonNullReference(xio_partition, "xio_partition"); if (xi_mode == ail.net.parser.Fsa.EMinimizationMode.ePartition) { BuildPartition(ref xio_partition); } else if (xi_mode == ail.net.parser.Fsa.EMinimizationMode.eTable) { BuildTable(ref xio_partition); } }