public static Nfa NewNfa(Spec spec) { Nfa nfa = new Nfa(); spec.nfa_states.Add(nfa); nfa.Edge = ''; return nfa; }
private static void ProcessStates(BitSet bset, Nfa current) { foreach (int current2 in bset) { List<Nfa> list = MakeNfa.spec.state_rules[current2]; list.Add(current); } }
public Nfa() { this.edge = '�'; this.cset = null; this.next = null; this.sibling = null; this.accept = null; this.anchor = 0; this.label = -1; this.states = null; }
public void mimic(Nfa nfa) { this.edge = nfa.edge; if (nfa.cset != null) { if (this.cset == null) { this.cset = new CharSet(); } this.cset.mimic(nfa.cset); } else { this.cset = null; } this.next = nfa.next; this.sibling = nfa.sibling; this.accept = nfa.accept; this.anchor = nfa.anchor; if (nfa.states != null) { this.states = new BitSet(nfa.states); return; } this.states = null; }
private static void discardNfa(Nfa nfa) { MakeNfa.spec.nfa_states.Remove(nfa); }
public NfaPair() { this.start = null; this.end = null; }
private string plab(Nfa state) { if (state == null) { return "--"; } return this.spec.nfa_states.IndexOf(state, 0, this.spec.nfa_states.Count).ToString(); }
/* * Function: e_closure * Description: Alters input set. */ public void e_closure() { Nfa state = null; /* * Debug checks */ #if DEBUG Utility.assert(null != nfa_set); Utility.assert(null != nfa_bit); #endif accept = null; anchor = Spec.NONE; accept_index = Utility.INT_MAX; /* * Create initial stack. */ Stack nfa_stack = new Stack(); int size = nfa_set.Count; for (int i = 0; i < size; i++) { state = (Nfa)nfa_set[i]; #if DEBUG Utility.assert(nfa_bit.Get(state.GetLabel())); #endif nfa_stack.Push(state); } /* * Main loop. */ while (nfa_stack.Count > 0) { Object o = nfa_stack.Pop(); if (o == null) { break; } state = (Nfa)o; #if OLD_DUMP_DEBUG if (null != state.GetAccept()) { Console.WriteLine("Looking at accepting state " + state.GetLabel() + " with <" + state.GetAccept().action + ">"); } #endif if (null != state.GetAccept() && state.GetLabel() < accept_index) { accept_index = state.GetLabel(); accept = state.GetAccept(); anchor = state.GetAnchor(); #if OLD_DUMP_DEBUG Console.WriteLine("Found accepting state " + state.GetLabel() + " with <" + state.GetAccept().action + ">"); #endif #if DEBUG Utility.assert(null != accept); Utility.assert(Spec.NONE == anchor || 0 != (anchor & Spec.END) || 0 != (anchor & Spec.START)); #endif } if (Nfa.EPSILON == state.GetEdge()) { if (state.GetNext() != null) { if (false == nfa_set.Contains(state.GetNext())) { #if DEBUG Utility.assert(false == nfa_bit.Get(state.GetNext().GetLabel())); #endif nfa_bit.Set(state.GetNext().GetLabel(), true); nfa_set.Add(state.GetNext()); nfa_stack.Push(state.GetNext()); } } if (null != state.GetSib()) { if (false == nfa_set.Contains(state.GetSib())) { #if DEBUG Utility.assert(false == nfa_bit.Get(state.GetSib().GetLabel())); #endif nfa_bit.Set(state.GetSib().GetLabel(), true); nfa_set.Add(state.GetSib()); nfa_stack.Push(state.GetSib()); } } } } if (null != nfa_set) { sort_states(); } }