本文整理汇总了C#中State.AddEpsilon方法的典型用法代码示例。如果您正苦于以下问题:C# State.AddEpsilon方法的具体用法?C# State.AddEpsilon怎么用?C# State.AddEpsilon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类State
的用法示例。
在下文中一共展示了State.AddEpsilon方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Optional
/// <summary>
/// Returns an automaton that accepts the union of the empty string and the language of the
/// given automaton.
/// </summary>
/// <param name="a">The automaton.</param>
/// <remarks>
/// Complexity: linear in number of states.
/// </remarks>
/// <returns>An automaton that accepts the union of the empty string and the language of the
/// given automaton.</returns>
public static Automaton Optional(Automaton a)
{
a = a.CloneExpandedIfRequired();
var s = new State();
s.AddEpsilon(a.Initial);
s.Accept = true;
a.Initial = s;
a.IsDeterministic = false;
a.ClearHashCode();
a.CheckMinimizeAlways();
return a;
}
示例2: Repeat
/// <summary>
/// Accepts the Kleene star (zero or more concatenated repetitions) of the language of the
/// given automaton. Never modifies the input automaton language.
/// </summary>
/// <param name="a">The automaton.</param>
/// <returns>
/// An automaton that accepts the Kleene star (zero or more concatenated repetitions)
/// of the language of the given automaton. Never modifies the input automaton language.
/// </returns>
/// <remarks>
/// Complexity: linear in number of states.
/// </remarks>
public static Automaton Repeat(Automaton a)
{
a = a.CloneExpanded();
var s = new State();
s.Accept = true;
s.AddEpsilon(a.Initial);
foreach (State p in a.GetAcceptStates())
{
p.AddEpsilon(s);
}
a.Initial = s;
a.IsDeterministic = false;
a.ClearHashCode();
a.CheckMinimizeAlways();
return a;
}
示例3: Union
/// <summary>
/// Returns an automaton that accepts the union of the languages of the given automata.
/// </summary>
/// <param name="automatons">The l.</param>
/// <returns>
/// An automaton that accepts the union of the languages of the given automata.
/// </returns>
/// <remarks>
/// Complexity: linear in number of states.
/// </remarks>
public static Automaton Union(IList<Automaton> automatons)
{
var ids = new HashSet<int>();
foreach (Automaton a in automatons)
{
ids.Add(RuntimeHelpers.GetHashCode(a));
}
bool hasAliases = ids.Count != automatons.Count;
var s = new State();
foreach (Automaton b in automatons)
{
if (b.IsEmpty)
{
continue;
}
Automaton bb = b;
bb = hasAliases ? bb.CloneExpanded() : bb.CloneExpandedIfRequired();
s.AddEpsilon(bb.Initial);
}
var automaton = new Automaton();
automaton.Initial = s;
automaton.IsDeterministic = false;
automaton.ClearHashCode();
automaton.CheckMinimizeAlways();
return automaton;
}