本文整理汇总了C#中NFA.AddAll方法的典型用法代码示例。如果您正苦于以下问题:C# NFA.AddAll方法的具体用法?C# NFA.AddAll怎么用?C# NFA.AddAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NFA
的用法示例。
在下文中一共展示了NFA.AddAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RepeatZeroOrMore
public static NFA RepeatZeroOrMore(NFA input)
{
var nfa = new NFA();
// Add everything from the input
nfa.AddAll(input);
// Create a new starting state, link it to the old accept state with Epsilon
nfa.StartState = new NFA.State();
nfa.States.Add(nfa.StartState);
NFA.State oldAcceptState = input.States.First(f => f.AcceptState);
nfa.Transitions.Add(new Transition<NFA.State>(nfa.StartState, oldAcceptState));
// Add epsilon link from old accept state of input to start, to allow for repetition
nfa.Transitions.Add(new Transition<NFA.State>(oldAcceptState, input.StartState));
// Create new accept state, link old accept state to new accept state with epsilon
var acceptState = new NFA.State { AcceptState = true };
nfa.States.Add(acceptState);
oldAcceptState.AcceptState = false;
nfa.Transitions.Add(new Transition<NFA.State>(oldAcceptState, acceptState));
return nfa;
}
示例2: And
public static NFA And(NFA first, NFA second)
{
// Create a new NFA and use the first NFAs start state as the starting point
var nfa = new NFA { StartState = first.StartState };
// Change all links in to first acceptstate to go to seconds
// start state
foreach (var edge in first.Transitions.Where(f => f.To.AcceptState))
{
edge.To = second.StartState;
}
// Remove acceptstate from first
first.States.Remove(first.States.First(f => f.AcceptState));
// Add all states and edges in both NFAs
// Second NFA already has an accept state, there is no need to create another one
nfa.AddAll(first);
nfa.AddAll(second);
return nfa;
}
示例3: Or
public static NFA Or(NFA a, NFA b)
{
var nfa = new NFA();
// Composite NFA contains all the and all edges in both NFAs
nfa.AddAll(a);
nfa.AddAll(b);
// Add a start state, link to both NFAs old start state with
// epsilon links
nfa.StartState = new NFA.State();
nfa.States.Add(nfa.StartState);
nfa.Transitions.Add(new Transition<NFA.State>(nfa.StartState, a.StartState));
nfa.Transitions.Add(new Transition<NFA.State>(nfa.StartState, b.StartState));
// Add a new accept state, link all old accept states to the new accept
// state with an epsilon link and remove the accept flag
var newAcceptState = new NFA.State { AcceptState = true };
foreach (var oldAcceptState in nfa.States.Where(f => f.AcceptState))
{
oldAcceptState.AcceptState = false;
nfa.Transitions.Add(new Transition<NFA.State>(oldAcceptState, newAcceptState));
}
nfa.States.Add(newAcceptState);
return nfa;
}