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


C# NFA.AddAll方法代码示例

本文整理汇总了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;
        }
开发者ID:uptown1919,项目名称:Piglet,代码行数:23,代码来源:NfaBuilder.cs

示例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;
        }
开发者ID:uptown1919,项目名称:Piglet,代码行数:22,代码来源:NfaBuilder.cs

示例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;
        }
开发者ID:uptown1919,项目名称:Piglet,代码行数:28,代码来源:NfaBuilder.cs


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