예제 #1
0
        public bool Match(NfaState start, IEnumerable <int> input)
        {
            List <NfaState> clist, nlist, t;

            clist = StartList(start, l1);
            nlist = l2;
            foreach (int ch in input)
            {
                Step(clist, ch, nlist);
                t     = clist;
                clist = nlist;
                nlist = t;
            }

            return(IsMatch(clist));
        }
예제 #2
0
        public static NfaFragment ZeroOrMore(NfaFragment inner)
        {
            var s = new NfaState(NfaStateKind.Split);

            s.Out.Add(inner.Start);
            foreach (var danglingInnerOut in inner.Outs)
            {
                danglingInnerOut.Add(s);
            }

            var result = new NfaFragment();

            result.Start = s;
            result.Outs.Add(s.Out);
            return(result);
        }
예제 #3
0
        private void AddState(List <NfaState> l, NfaState s)
        {
            if (s == null || s.LastList == listid)
            {
                return;
            }

            s.LastList = listid;

            if (s.Kind == NfaStateKind.Split)
            {
                AddStates(l, s.Out);
            }
            else
            {
                l.Add(s);
            }
        }