public STb <F, T, S> Mk(string regex, params Tuple <string, STb <F, T, S> >[] args) { var K = args.Length; bool isLoop; var patternAutomataPairs = solver.CharSetProvider.ConvertCaptures(regex, out isLoop); var captureAutomata = new Dictionary <string, Automaton <BDD> >(); var stbs = new Dictionary <string, STb <F, T, S> >(); foreach (var arg in args) { if (stbs.ContainsKey(arg.Item1) || string.IsNullOrEmpty(arg.Item1)) { throw new AutomataException(AutomataExceptionKind.InvalidArguments); } stbs[arg.Item1] = arg.Item2; } foreach (var pair in patternAutomataPairs) { if (pair.Item1 != "") { captureAutomata[pair.Item1] = pair.Item2; } } var captureSortPos = new Dictionary <string, int>(); var captureSortName = new Dictionary <string, string>(); for (int i = 0; i < args.Length; i += 1) { captureSortName[args[i].Item1] = args[i].Item2.OutputSort.ToString(); captureSortPos[args[i].Item1] = i; } if (Array.Exists(patternAutomataPairs, pair => (pair.Item1 != "" && !captureSortName.ContainsKey(pair.Item1)))) { throw new AutomataException(AutomataExceptionKind.InvalidArguments); } S[] argSorts = new S[K]; for (int i = 0; i < K; i++) { if (!captureAutomata.ContainsKey(args[i].Item1)) { throw new AutomataException(AutomataExceptionKind.InvalidArguments); } if (!args[i].Item2.OutputSort.Equals(args[i].Item2.RegisterSort)) { throw new AutomataException(AutomataExceptionKind.InvalidArguments); } argSorts[i] = args[i].Item2.OutputSort; } var regSort = solver.MkTupleSort(argSorts); var regVar = solver.MkVar(1, regSort); var initReg = solver.MainSolver.FindOneMember(solver.MkEq(regVar, regVar)).Value; var inpVar = solver.MkVar(0, solver.CharSort); var stb = new STb <F, T, S>(solver, "stb", solver.CharSort, regSort, regSort, initReg, 0); var nextStateId = 0; var stateIdMap = new Dictionary <Tuple <int, int, int>, int>(); Func <int, int, int, int> MkState = (n, q1, q2) => { int p; var nq = new Tuple <int, int, int>(n, q1, q2); if (stateIdMap.TryGetValue(nq, out p)) { return(p); } else { p = nextStateId; nextStateId += 1; stateIdMap[nq] = p; return(p); } }; var resSTB = new STb <F, T, S>(solver, "STB", solver.CharSort, solver.CharSort, solver.UnitSort, solver.UnitConst, 0); resSTB.AssignRule(0, new BaseRule <T>(new Sequence <T>(solver.MkCharVar(0)), solver.UnitConst, 0)); resSTB.AssignFinalRule(0, new BaseRule <T>(Sequence <T> .Empty, solver.UnitConst, 0)); for (int i = 0; i < patternAutomataPairs.Length; i++) { var aut = patternAutomataPairs[i].Item2; if (patternAutomataPairs[i].Item1 == "") { var autSTMoves = new List <Move <Rule <T> > >(); foreach (var move in aut.GetMoves()) { //move cannot be epsilon here var cond = solver.ConvertFromCharSet(move.Label); autSTMoves.Add(Move <Rule <T> > .Create(move.SourceState, move.TargetState, Rule <T> .Mk(cond, solver.UnitConst))); } foreach (var f in aut.GetFinalStates()) { //collect guards of all moves exitingfrom f var allGuardsFromF = solver.CharSetProvider.False; foreach (var fmove in aut.GetMovesFrom(f)) { allGuardsFromF = solver.CharSetProvider.MkOr(allGuardsFromF, fmove.Label); } var elseFromF = solver.ConvertFromCharSet(solver.CharSetProvider.MkNot(allGuardsFromF)); autSTMoves.Add(Move <Rule <T> > .Create(f, f, Rule <T> .Mk(elseFromF, solver.UnitConst, solver.MkCharVar(0)))); autSTMoves.Add(Move <Rule <T> > .Create(f, f, Rule <T> .MkFinal(solver.True))); } var autST = ST <F, T, S> .Create(solver, patternAutomataPairs[i].Item1, solver.UnitConst, solver.CharSort, solver.CharSort, solver.UnitSort, aut.InitialState, autSTMoves); var autSTb = autST.ToSTb(); resSTB = resSTB.Compose(autSTb); } else { var stb1 = stbs[patternAutomataPairs[i].Item1]; if (!stb1.InputSort.Equals(solver.CharSort)) { throw new AutomataException(AutomataExceptionKind.InvalidArguments); } var autSTMoves = new List <Move <Rule <T> > >(); foreach (var move in aut.GetMoves()) { //move cannot be epsilon here var cond = solver.ConvertFromCharSet(move.Label); autSTMoves.Add(Move <Rule <T> > .Create(move.SourceState, move.TargetState, Rule <T> .Mk(cond, solver.UnitConst, inpVar))); } foreach (var f in aut.GetFinalStates()) { autSTMoves.Add(Move <Rule <T> > .Create(f, f, Rule <T> .MkFinal(solver.True))); } var autST = ST <F, T, S> .Create(solver, patternAutomataPairs[i].Item1, solver.UnitConst, solver.CharSort, solver.CharSort, solver.UnitSort, aut.InitialState, autSTMoves); var autSTb = autST.ToSTb(); var stb2 = autSTb.Compose(stb1); foreach (var f in stb.States) { var frule = stb.GetFinalRuleFrom(f); if (frule.IsNotUndef) { //var frule1 = } } } } throw new NotImplementedException(); }
public override IEnumerable <Move <Rule <TERM> > > EnumerateMoves(IContextCore <TERM> solver, int source, TERM guard) { yield return(Move <Rule <TERM> > .Create(source, state, Rule <TERM> .Mk(guard, register, yields.ToArray()))); }