本文整理汇总了C#中NFA.AddTransition方法的典型用法代码示例。如果您正苦于以下问题:C# NFA.AddTransition方法的具体用法?C# NFA.AddTransition怎么用?C# NFA.AddTransition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NFA
的用法示例。
在下文中一共展示了NFA.AddTransition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NFATests
public void NFATests()
{
var a = new NFA<char>();
// "a" automaton
a.AddTransition(a.Start, new State { Final = true }, 'a');
a.Initial();
a.Trigger('a');
Assert.That(a.Current.Contains(a.LastAdded), Is.True);
a.Initial();
Assert.That(() => a.Trigger('b'), Throws.TypeOf<StateNotFoundException>());
// "abcd" automaton
a = new NFA<char>();
a.AddTransition(a.Start, new State(), 'a');
a.AddTransition(a.LastAdded, new State(), 'b');
a.AddTransition(a.LastAdded, new State(), 'c');
a.AddTransition(a.LastAdded, new State { Final = true }, 'd');
a.Initial();
foreach (char c in "abcd") {
Assert.That(a.Current.Contains(a.LastAdded), Is.False);
a.Trigger(c);
}
Assert.That(a.Current.Contains(a.LastAdded), Is.True);
Assert.That(() => a.Trigger('b'), Throws.TypeOf<StateNotFoundException>());
}
示例2: AddExpression
public void AddExpression(string name, string regex)
{
using (var stream = new StringReader(InfixToPostfix.Convert(regex)))
{
while (stream.Peek() != -1)
{
var c = (char) stream.Read();
switch (c)
{
case '.': _stack.Concatenate(); break;
case '|': _stack.Unite(); break;
case '*': _stack.Iterate(); break;
case '+': _stack.AtLeast(); break;
case '?': _stack.Maybe(); break;
default:
var a = new NFA<char>();
a.AddTransition(a.Start, new State(), c == '\\' ? Escape((char) stream.Read()) : c);
_stack.Push(a);
break;
}
}
var top = _stack.Peek();
top.LastAdded.Final = true;
top.SetName(top.LastAdded, name);
}
}
示例3: AddExpression
public void AddExpression(string name, string regex)
{
var stream = new StringReader(InfixToPostfix.Convert(regex));
while (stream.Peek() != -1)
{
var c = (char) stream.Read();
NFA<char> a;
switch (c)
{
case '.':
_stack.Concatenate();
break;
case '|':
_stack.Unite();
break;
case '*':
_stack.Iterate();
break;
case '+':
_stack.AtLeast();
break;
case '?':
_stack.Maybe();
break;
case '\\':
char n = (char) stream.Read();
a = new NFA<char>();
a.AddTransition(a.Start, new State(), Escape(n));
_stack.Push(a);
break;
default:
a = new NFA<char>();
a.AddTransition(a.Start, new State(), c);
_stack.Push(a);
break;
}
}
var automaton = _stack.Peek();
automaton.LastAdded.Final = true;
automaton.SetName(automaton.LastAdded, name);
}