private static bool CheckForAllStates(Expr output, Func <Expr, bool> phi) { if (output.ASTKind != Z3_ast_kind.Z3_APP_AST) { throw new AutomataException(AutomataExceptionKind.TreeTransducer_UnexpectedOutputExpr); } var f = output.FuncDecl; var args = output.Args; if (TreeTheory.IsTrans(f)) { //check the state condition for the first argument bool res = phi(args[0]); return(res); } else //must be constructor { for (int i = 1; i < args.Length; i++) { if (!CheckForAllStates(args[i], phi)) { return(false); } } return(true); } }
internal RankedAlphabet( TreeTheory tt, string[] symbols, Dictionary <string, int> idMap, Sort alphabetSort, Sort nodeSort, int[] ranks, FuncDecl[] constructors, FuncDecl[][] accessors, FuncDecl[] testers, FuncDecl acceptor, Expr[] vars ) { this.tt = tt; this.symbols = new List <string>(symbols).AsReadOnly(); this.idMap = idMap; this.alphabetSort = alphabetSort; this.nodeSort = nodeSort; this.ranks = ranks; this.constructors = constructors; this.accessors = accessors; this.testers = testers; this.acceptor = acceptor; this.vars = vars; this.trans = tt.GetTrans(alphabetSort, alphabetSort); this.emptyAcceptor = TreeTransducer.MkEmpty(this); this.fullAcceptor = TreeTransducer.MkFull(this); this.idAut = TreeTransducer.MkId(this); this.symbolsOfRank = new Dictionary <int, List <FuncDecl> >(); for (int i = 0; i < ranks.Length; i++) { var r = ranks[i]; if (!symbolsOfRank.ContainsKey(r)) { symbolsOfRank[r] = new List <FuncDecl>(); } symbolsOfRank[r].Add(constructors[i]); } var attrDomain = tt.Z.MkFreshFuncDecl("_", new Sort[] { nodeSort }, tt.Z.BoolSort); this.attrExpr = tt.Z.MkApp(attrDomain, vars[0]); tt.Z.AssertAxiom(this.attrExpr, tt.Z.True, vars[0]); }
/// <summary> /// Enumerates all pairs Expr[]{state,child_variable}. /// </summary> static IEnumerable <Expr[]> GetStatesOf(Expr t) { if (t.ASTKind == Z3_ast_kind.Z3_APP_AST) { var args = t.Args; if (TreeTheory.IsTrans(t.FuncDecl)) { yield return(args); } else { for (int i = 1; i < args.Length; i++) { foreach (var s in GetStatesOf(args[i])) { yield return(s); } } } } }
/// <summary> /// Include all states in the output also in the lookahead. /// </summary> public TreeRule Normalize() { if (output == null) { return(this); } ExprSet[] given = new ExprSet[lookahead.Length]; for (int i = 0; i < lookahead.Length; i++) { given[i] = new ExprSet(lookahead[i]); } foreach (var state_child in GetStatesOf(output)) { if (!TreeTheory.IsIdentityState(state_child[0])) //filter out identity states { given[(GetVariableIndex(state_child[1])) - 1].Add(state_child[0]); } } return(new TreeRule(state, symbol, guard, output, given)); }