当前位置: 首页>>代码示例>>C#>>正文


C# NFA.AddTransition方法代码示例

本文整理汇总了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>());
        }
开发者ID:surenkov,项目名称:UCP,代码行数:29,代码来源:StateMachineTests.cs

示例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);
            }
        }
开发者ID:surenkov,项目名称:UCP,代码行数:27,代码来源:RegexEngine.cs

示例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);
 }
开发者ID:Davidyuk,项目名称:UCP,代码行数:41,代码来源:RegexBuilder.cs


注:本文中的NFA.AddTransition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。