Exemple #1
0
 public DiGraph reverse()
 {
     DiGraph R = new DiGraph(V);
     for (int v = 0; v < V; v++)
         foreach (int w in Adj(v))
             R.addEdge(w, v);
     return R;
 }
Exemple #2
0
        private int M;     // number of states

        public NFA(string regexp)
        { // Create the NFA for the given regular expression.
            Stack <int> ops = new Stack <int>();

            re = regexp.ToCharArray();
            M  = re.Length;
            G  = new DiGraph(M + 1);
            for (int i = 0; i < M; i++)
            {
                int lp = i;
                if (re[i] == '(' || re[i] == '|')
                {
                    ops.Push(i);
                }
                else if (re[i] == ')')
                {
                    int or = ops.Pop();
                    if (re[or] == '|')
                    {
                        lp = ops.Pop();
                        G.addEdge(lp, or + 1);
                        G.addEdge(or, i);
                    }
                    else
                    {
                        lp = or;
                    }
                }
                if (i < M - 1 && re[i + 1] == '*') // lookahead
                {
                    G.addEdge(lp, i + 1);
                    G.addEdge(i + 1, lp);
                }
                if (re[i] == '(' || re[i] == '*' || re[i] == ')')
                {
                    G.addEdge(i, i + 1);
                }
            }
        }
Exemple #3
0
        public DiGraph reverse()
        {
            DiGraph R = new DiGraph(V);

            for (int v = 0; v < V; v++)
            {
                foreach (int w in Adj(v))
                {
                    R.addEdge(w, v);
                }
            }
            return(R);
        }
Exemple #4
0
        private char[] re; // match transitions

        #endregion Fields

        #region Constructors

        public NFA(string regexp)
        {
            // Create the NFA for the given regular expression.
            Stack<int> ops = new Stack<int>();
            re = regexp.ToCharArray();
            M = re.Length;
            G = new DiGraph(M + 1);
            for (int i = 0; i < M; i++)
            {
                int lp = i;
                if (re[i] == '(' || re[i] == '|')
                    ops.Push(i);
                else if (re[i] == ')')
                {
                    int or = ops.Pop();
                    if (re[or] == '|')
                    {
                        lp = ops.Pop();
                        G.addEdge(lp, or + 1);
                        G.addEdge(or, i);
                    }
                    else lp = or;
                }
                if (i < M - 1 && re[i + 1] == '*') // lookahead
                {
                    G.addEdge(lp, i + 1);
                    G.addEdge(i + 1, lp);
                }
                if (re[i] == '(' || re[i] == '*' || re[i] == ')')
                    G.addEdge(i, i + 1);
            }
        }