private static INfa Any() { var start = new NfaState(); var end = new NfaState(); start.AddTransistion(new TerminalNfaTransition(new AnyTerminal(), end)); return(new Nfa(start, end)); }
private static INfa Empty() { var start = new NfaState(); var end = new NfaState(); start.AddTransistion(new NullNfaTransition(end)); return(new Nfa(start, end)); }
private static Nfa Any() { var start = new NfaState(); var end = new NfaState(); start.AddTransition(AnyTerminal.Instance, end); return(new Nfa(start, end)); }
private static Nfa KleenePlus(Nfa nfa) { var end = new NfaState(); nfa.End.AddEpsilon(end); nfa.End.AddEpsilon(nfa.Start); return(new Nfa(nfa.Start, end)); }
private static Nfa Empty() { var start = new NfaState(); var end = new NfaState(); start.AddEpsilon(end); return(new Nfa(start, end)); }
private static INfa KleenePlus(INfa nfa) { var end = new NfaState(); nfa.End.AddTransistion(new NullNfaTransition(end)); nfa.End.AddTransistion(new NullNfaTransition(nfa.Start)); return(new Nfa(nfa.Start, end)); }
public static Nfa Single(Atom terminal) { var start = new NfaState(); var end = new NfaState(); start.Add(terminal, end); return(new Nfa(start, end)); }
public override Nfa GenerateNfa(bool ignoreCase) { if (!transformed) { if (Options.getIgnoreCase() || ignoreCase) { ToCaseNeutral(); SortDescriptors(); } if (Negated) { RemoveNegation(); // This also sorts the list } else { SortDescriptors(); } } if (descriptors.Count == 0 && !Negated) { CSharpCCErrors.SemanticError(this, "Empty character set is not allowed as it will not match any character."); return(new Nfa()); } transformed = true; Nfa retVal = new Nfa(); NfaState startState = retVal.Start; NfaState finalState = retVal.End; int i; for (i = 0; i < descriptors.Count; i++) { if (descriptors[i] is SingleCharacter) { startState.AddChar(((SingleCharacter)descriptors[i]).Character); } else // if (descriptors.get(i) instanceof CharacterRange) { CharacterRange cr = (CharacterRange)descriptors[i]; if (cr.Left == cr.Right) { startState.AddChar(cr.Left); } else { startState.AddRange(cr.Left, cr.Right); } } } startState.next = finalState; return(retVal); }
private static Nfa Character(RegexCharacterClassCharacter character, bool negate) { var start = new NfaState(); var end = new NfaState(); var terminal = CreateTerminalForCharacter(character.Value, character.IsEscaped, negate); start.AddTransition(terminal, end); return(new Nfa(start, end)); }
private static INfa Optional(INfa nfa) { var start = new NfaState(); var end = new NfaState(); start.AddTransistion(new NullNfaTransition(nfa.Start)); start.AddTransistion(new NullNfaTransition(end)); nfa.End.AddTransistion(new NullNfaTransition(end)); return(new Nfa(start, end)); }
private static Nfa Optional(Nfa nfa) { var start = new NfaState(); var end = new NfaState(); start.AddEpsilon(nfa.Start); start.AddEpsilon(end); nfa.End.AddEpsilon(end); return(new Nfa(start, end)); }
/// <summary> /// 根据当前的正则表达式构造 NFA。 /// </summary> /// <param name="nfa">要构造的 NFA。</param> internal override void BuildNfa(Nfa nfa) { left.BuildNfa(nfa); NfaState head = nfa.HeadState; NfaState tail = nfa.TailState; right.BuildNfa(nfa); tail.Add(nfa.HeadState); nfa.HeadState = head; }
public static Nfa EmulateTrivial(char character) { NfaBuilder builder = new NfaBuilder(); NfaState head = builder.CreateState(); NfaState tail = builder.CreateState(); Transition.Create(head, tail, character); return(builder.Create(head, tail)); }
private static NfaState[] CreateStates(int count) { var states = new NfaState[count]; for (int i = 0; i < states.Length; i++) { states[i] = new EntityNfaState(i); } return(states); }
private int DFAStateNumber(NfaState state) { for (var i = 0; i < m_dfa.Count; ++i) { if (m_dfa[i].NFAStates.SetEquals(state.NFAStates)) { return(i); } } return(-1); }
public void NfaClosuresFromSameSetShouldBeEqual() { var state1 = new NfaState(); var state2 = new NfaState(); var sut1 = new NfaClosure(new[] { state1, state2 }, state1); var sut2 = new NfaClosure(new[] { state2, state1 }, state1); Assert.IsTrue(sut1.Equals(sut2)); Assert.AreEqual(sut1.GetHashCode(), sut1.GetHashCode()); }
private static INfa Character(RegexCharacter character) { var start = new NfaState(); var end = new NfaState(); var terminal = new CharacterTerminal(character.Value); var transition = new TerminalNfaTransition( terminal: terminal, target: end); start.AddTransistion(transition); return(new Nfa(start, end)); }
public void NfaClosureShouldNewWithEmptyStates() { var state = new NfaState(); var sut = new NfaClosure(Enumerable.Empty <NfaState>(), state); Assert.IsNotNull(sut); Assert.IsNotNull(sut.Set); Assert.AreEqual(0, sut.Set.Count); Assert.IsNotNull(sut.State); Assert.AreEqual(false, sut.State.IsFinal); }
public void NfaClosureShouldNewWithOneState() { var state = new NfaState(); var sut = new NfaClosure(Enumerable.Repeat(state, 1), state); Assert.IsNotNull(sut); Assert.IsNotNull(sut.Set); Assert.AreEqual(1, sut.Set.Count); Assert.IsNotNull(sut.State); Assert.AreEqual(true, sut.State.IsFinal); }
public NfaFragment Visit(CharSetNode node) { var s = new NfaState(node.Characters); return(new NfaFragment { Start = s, Outs = new List <List <NfaState> > { s.Out } }); }
public void NfaClosureShouldNewWithTwoStates() { var state1 = new NfaState(); var state2 = new NfaState(); var sut = new NfaClosure(new [] { state1, state2 }, state1); Assert.IsNotNull(sut); Assert.IsNotNull(sut.Set); Assert.AreEqual(2, sut.Set.Count); Assert.IsNotNull(sut.State); Assert.AreEqual(true, sut.State.IsFinal); }
public INfa Union(INfa nfa) { var newStart = new NfaState(); var newEnd = new NfaState(); newStart.AddTransistion(new NullNfaTransition(Start)); newStart.AddTransistion(new NullNfaTransition(nfa.Start)); End.AddTransistion(new NullNfaTransition(newEnd)); nfa.End.AddTransistion(new NullNfaTransition(newEnd)); return new Nfa(newStart, newEnd); }
public Nfa Union(Nfa other) { var newStart = new NfaState(); var newEnd = new NfaState(); newStart.AddEpsilon(Start); newStart.AddEpsilon(other.Start); End.AddEpsilon(newEnd); other.End.AddEpsilon(newEnd); return(new Nfa(newStart, newEnd)); }
public Nfa Kleene() { var newStart = new NfaState(); var newEnd = new NfaState(); newStart.AddEpsilon(Start); newStart.AddEpsilon(newEnd); newEnd.AddEpsilon(Start); End.AddEpsilon(newEnd); return(new Nfa(newStart, newEnd)); }
private static Nfa Union(Nfa first, Nfa second) { var start = new NfaState(); var end = new NfaState(); start.AddEpsilon(first.Start); start.AddEpsilon(second.Start); first.End.AddEpsilon(end); second.End.AddEpsilon(end); return(new Nfa(start, end)); }
public INfa Union(INfa nfa) { var newStart = new NfaState(); var newEnd = new NfaState(); newStart.AddTransistion(new NullNfaTransition(Start)); newStart.AddTransistion(new NullNfaTransition(nfa.Start)); End.AddTransistion(new NullNfaTransition(newEnd)); nfa.End.AddTransistion(new NullNfaTransition(newEnd)); return(new Nfa(newStart, newEnd)); }
public INfa Kleene() { var newStart = new NfaState(); var newEnd = new NfaState(); newStart.AddTransistion(new NullNfaTransition(Start)); newStart.AddTransistion(new NullNfaTransition(newEnd)); newEnd.AddTransistion(new NullNfaTransition(Start)); End.AddTransistion(new NullNfaTransition(newEnd)); return new Nfa(newStart, newEnd); }
public INfa Kleene() { var newStart = new NfaState(); var newEnd = new NfaState(); newStart.AddTransistion(new NullNfaTransition(Start)); newStart.AddTransistion(new NullNfaTransition(newEnd)); newEnd.AddTransistion(new NullNfaTransition(Start)); End.AddTransistion(new NullNfaTransition(newEnd)); return(new Nfa(newStart, newEnd)); }
/// <summary> /// 根据当前的正则表达式构造 NFA。 /// </summary> /// <param name="nfa">要构造的 NFA。</param> internal override void BuildNfa(Nfa nfa) { NfaState head = nfa.NewState(); NfaState tail = nfa.NewState(); left.BuildNfa(nfa); head.Add(nfa.HeadState); nfa.TailState.Add(tail); right.BuildNfa(nfa); head.Add(nfa.HeadState); nfa.TailState.Add(tail); nfa.HeadState = head; nfa.TailState = tail; }
public void Apply(NfaState state) { if (!Add(state)) { return; } var epsilonStates = state.EpsilonStates; var cnt = epsilonStates.Length; for (var i = 0; i < cnt; i++) { Add(epsilonStates[i]); } }
public override Nfa GenerateNfa(bool ignoreCase) { Nfa retVal = new Nfa(); NfaState startState = retVal.Start; NfaState finalState = retVal.End; Nfa temp = RegularExpression.GenerateNfa(ignoreCase); startState.AddMove(temp.Start); temp.End.AddMove(temp.Start); temp.End.AddMove(finalState); return(retVal); }
/// <summary> /// 根据当前的正则表达式构造 NFA。 /// </summary> /// <param name="nfa">要构造的 NFA。</param> internal override void BuildNfa(Nfa nfa) { innerExp.BuildNfa(nfa); if (TrailingExpression != null) { NfaState head = nfa.HeadState; TrailingHeadState = nfa.TailState; TrailingExpression.BuildNfa(nfa); TrailingHeadState.Add(nfa.HeadState); nfa.HeadState = head; TrailingHeadState.StateType = NfaStateType.TrailingHead; nfa.TailState.StateType = NfaStateType.Trailing; } }