public DiaGraphAPI BuildEpsilonTransitionDiGraph() { DiaGraphAPI G = new DiaGraphAPI(M + 1); Stack <int> ops = new Stack <int>(); 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] == '*') { G.AddEdge(lp, i + 1); G.AddEdge(i + 1, lp); } if (re[i] == '(' || re[i] == '*' || re[i] == ')') { G.AddEdge(i, i + 1); } } return(G); }
public NFA(string regExp) { M = regExp.Length; re = regExp.ToCharArray(); G = BuildEpsilonTransitionDiGraph(); }