示例#1
0
        public bool recognizes(string txt)
        { // Does the NFA recognize txt?
            List <int>  pc  = new List <int>();
            DirectedDFS dfs = new DirectedDFS(G, 0);

            for (int v = 0; v < G.V; v++)
            {
                if (dfs.Marked(v))
                {
                    pc.Add(v);
                }
            }
            foreach (char t in txt)
            {// Compute possible NFA states for txt[i+1].
                List <int> match = (from v in pc where v < M where re[v] == t || re[v] == '.' select v + 1).ToList();
                pc  = new List <int>();
                dfs = new DirectedDFS(G, match);
                for (int v = 0; v < G.V; v++)
                {
                    if (dfs.Marked(v))
                    {
                        pc.Add(v);
                    }
                }
            }
            return(pc.Any(v => v == M));
        }
示例#2
0
 public bool recognizes(string txt)
 {
     // Does the NFA recognize txt?
     List<int> pc = new List<int>();
     DirectedDFS dfs = new DirectedDFS(G, 0);
     for (int v = 0; v < G.V; v++)
         if (dfs.Marked(v))
             pc.Add(v);
     foreach (char t in txt)
     {// Compute possible NFA states for txt[i+1].
         List<int> match = (from v in pc where v < M where re[v] == t || re[v] == '.' select v + 1).ToList();
         pc = new List<int>();
         dfs = new DirectedDFS(G, match);
         for (int v = 0; v < G.V; v++)
             if (dfs.Marked(v))
                 pc.Add(v);
     }
     return pc.Any(v => v == M);
 }