private Untangle _untangle(Tuple <Trans, int> t1, Tuple <Trans, int> t2) { CharRange a = (CharRange)t1.Item1; CharRange b = (CharRange)t2.Item1; Untangle u = Untangle.untangle(a.From, a.To, b.From, b.To); return(u); }
public static String ToDot(FA fa) { Set <int> allStates = Utils.make_set(Utils.transitiveClosure(fa.startState, (s) => Utils.make_set(Utils.GetOrDefault(fa.tg, s, new List <Tuple <Trans, int> >()).Select(p => p.Item2)))); StringBuilder sb = new StringBuilder(); p(sb, "digraph NFA {"); p(sb, "rankdir=LR;"); foreach (int s in allStates) { if (fa.acceptingStates.Contains(s)) { p(sb, string.Format("s{0}[fontsize=11, label=\"{1}\", shape=doublecircle, fixedsize=true, width=.6];", s, s)); } else { p(sb, String.Format( "s{0}[fontsize=11, label=\"{1}\", shape=circle, fixedsize=true, width=.55, peripheries=1];", s, s)); } } foreach (KeyValuePair <int, List <Tuple <Trans, int> > > kv in fa.tg) { int from = kv.Key; foreach (Tuple <Trans, int> pair in kv.Value) { Trans t = pair.Item1; int to = pair.Item2; string label = null; if (t is Epsilon) { label = "ε"; } else if (t is CharRange) { CharRange r = (CharRange)t; label = string.Format("{{{0}..{1}}}", r.From, r.To); } else { throw new System.ArgumentException(t.ToString()); } p(sb, String.Format( "s{0} -> s{1} [fontsize=11, fontname=\"Courier\", arrowsize=.7, label = \"{2}\", arrowhead = normal];", from, to, label)); } } p(sb, "}"); return(sb.ToString()); }
public override bool Equals(object o) { CharRange c = o as CharRange; if (c == null) { return(false); } return(From == c.From && To == c.To); }
private bool hasCommon(Trans a, Trans b) { if (a is CharRange && b is CharRange) { CharRange aa = a as CharRange; CharRange bb = b as CharRange; if (bb.From > aa.To || aa.From > bb.To) { return(false); } return(true); /* * // The following is equivalent to the above (from DeMorgan's laws) * // even though the above is much more obvious. Math is cool like that. * * // To show it, here are diagrams: * // Case #1 * // |a---------------------| * // |b------------------| * * // Case #2 * // |a---------------------| * // |b------------------| * * // Case #3 * // |a----| * // |b------------------| * * // Case #4 * // |a---------------------| * // |b-----------| * * * if(bb.From <= aa.To && aa.From <= bb.To) * { * return true; * } * return false; */ } return(false); }
public Untangle(List <CharRange> _onlyA, CharRange _common, List <CharRange> _onlyB) { onlyA = _onlyA; common = _common; onlyB = _onlyB; }