Exemple #1
0
 internal AcceptorBase(FuncDecl symbol, Expr guard, ExprSet[] lookahead)
 {
     this.symbol = symbol;
     this.guard = guard;
     this.lookahead = lookahead;
     this.lhs = new Pair<FuncDecl, Sequence<ExprSet>>(symbol, new Sequence<ExprSet>(lookahead));
 }
Exemple #2
0
 private IEnumerable <Tuple <Expr, ExprSet[]> > EnumerateCombinedRules(ConsList <Expr> state_set, FuncDecl func,
                                                                       Func <Expr, FuncDecl, IEnumerable <TreeRule> > GetRules)
 {
     if (state_set.Rest == null)
     {
         foreach (var rule in GetRules(state_set.First, func))
         {
             yield return(new Tuple <Expr, ExprSet[]>(rule.Guard, rule.lookahead));
         }
     }
     else
     {
         foreach (var rule in GetRules(state_set.First, func))
         {
             var childStateSets = rule.lookahead;
             foreach (var rule_base in EnumerateCombinedRules(state_set.Rest, func, GetRules))
             {
                 var guard = tt.Z.MkAndSimplify(rule.Guard, rule_base.Item1);
                 if (!guard.Equals(tt.Z.False))
                 {
                     var childStateSets1 = new ExprSet[childStateSets.Length];
                     for (int i = 0; i < childStateSets.Length; i++)
                     {
                         childStateSets1[i] = new ExprSet(childStateSets[i]);
                         childStateSets1[i].AddRange(rule_base.Item2[i]);
                     }
                     yield return(new Tuple <Expr, ExprSet[]>(guard, childStateSets1));
                 }
             }
         }
     }
 }
Exemple #3
0
        /// <summary>
        /// Make a new acceptor rule where k = lookahead.Length is the rank of the symbol.
        /// </summary>
        /// <param name="state">top state of the rule</param>
        /// <param name="symbol">symbol of the alphabet</param>
        /// <param name="guard">attribute guard</param>
        /// <param name="lookahead">bottom state sets of the rule</param>
        public TreeRule MkAcceptorRule(int state, string symbol, Expr guard, int[][] lookahead)
        {
            int symb_id = GetId(symbol);
            int k       = ranks[symb_id];

            if (state < 0 || lookahead == null || lookahead.Length != k ||
                Array.Exists(lookahead, B => (B != null && Array.Exists(B, b => b < 0))))
            {
                throw new AutomataException(AutomataExceptionKind.RankedAlphabet_InvalidAcceptorRuleArguments);
            }
            FuncDecl func = constructors[symb_id];

            ExprSet[] termSets = new ExprSet[k];
            for (int i = 0; i < k; i++)
            {
                termSets[i] = new ExprSet();
                if (lookahead[i] != null)
                {
                    for (int j = 0; j < lookahead[i].Length; j++)
                    {
                        termSets[i].Add(tt.Z.MkInt(lookahead[i][j]));
                    }
                }
            }
            var acc = new TreeRule(tt.Z.MkInt(state), func, guard, null, termSets);

            return(acc);
        }
Exemple #4
0
        /// <summary>
        /// Make a tree rule from the input alphabet to the output alphabet.
        /// </summary>
        /// <param name="inputAlphabet">input alphabet</param>
        /// <param name="outputAlphabet">output alphabet</param>
        /// <param name="state">source state</param>
        /// <param name="symbol">a ranked symbol of the input alphabet</param>
        /// <param name="guard">attribute guard</param>
        /// <param name="output">output tree</param>
        /// <param name="lookahead">domain restriction states</param>
        public TreeRule MkTreeRule(RankedAlphabet inputAlphabet, RankedAlphabet outputAlphabet, int state, string symbol, Expr guard, Expr output, params int[][] lookahead)
        {
            var A      = inputAlphabet;
            var B      = outputAlphabet;
            var constr = A.GetConstructor(symbol);

            CheckAttribute(guard, A);

            if (A.GetRank(symbol) != lookahead.Length)
            {
                throw new AutomataException(AutomataExceptionKind.TreeTheory_RankMismatch);
            }

            ExprSet[] la = new ExprSet[lookahead.Length];
            int       j  = 0;

            for (int i = 0; i < lookahead.Length; i++)
            {
                la[i] = new ExprSet();
                for (j = 0; j < lookahead[i].Length; j++)
                {
                    la[i].Add(Z.MkNumeral(lookahead[i][j], Z.IntSort));
                }
            }

            var outp = (output == null ? null : NormalizeOutput(output, A, B, A.GetRank(symbol)));

            return(new TreeRule(Z.MkInt(state), constr, guard, outp, la));
        }
Exemple #5
0
 internal AcceptorBase(FuncDecl symbol, Expr guard, int rank)
 {
     this.symbol = symbol;
     this.guard = guard;
     ExprSet[] ts = new ExprSet[rank];
     for (int i = 0; i < rank; i++)
         ts[i] = new ExprSet();
     lookahead = ts;
 }
Exemple #6
0
 internal AcceptorBase(FuncDecl symbol, Expr guard, int rank)
 {
     this.symbol = symbol;
     this.guard  = guard;
     ExprSet[] ts = new ExprSet[rank];
     for (int i = 0; i < rank; i++)
     {
         ts[i] = new ExprSet();
     }
     lookahead = ts;
 }
Exemple #7
0
        /// <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));
        }
Exemple #8
0
        /// <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);
        }
 private IEnumerable<Pair<Expr, ExprSet[]>> EnumerateCombinedRules(ConsList<Expr> state_set, FuncDecl func, 
     Func<Expr,FuncDecl,IEnumerable<TreeRule>> GetRules)
 {
     if (state_set.Rest == null)
         foreach (var rule in GetRules(state_set.First, func))
             yield return new Pair<Expr, ExprSet[]>(rule.Guard, rule.lookahead);
     else
     {
         foreach (var rule in GetRules(state_set.First, func))
         {
             var childStateSets = rule.lookahead;
             foreach (var rule_base in EnumerateCombinedRules(state_set.Rest, func, GetRules))
             {
                 var guard = tt.Z.MkAndSimplify(rule.Guard, rule_base.First);
                 if (!guard.Equals(tt.Z.False))
                 {
                     var childStateSets1 = new ExprSet[childStateSets.Length];
                     for (int i = 0; i < childStateSets.Length; i++)
                     {
                         childStateSets1[i] = new ExprSet(childStateSets[i]);
                         childStateSets1[i].AddRange(rule_base.Second[i]);
                     }
                     yield return new Pair<Expr, ExprSet[]>(guard, childStateSets1);
                 }
             }
         }
     }
 }
 /// <summary>
 /// Make a new acceptor rule where k = lookahead.Length is the rank of the symbol.
 /// </summary>
 /// <param name="state">top state of the rule</param>
 /// <param name="symbol">symbol of the alphabet</param>
 /// <param name="guard">attribute guard</param>
 /// <param name="lookahead">bottom state sets of the rule</param>
 public TreeRule MkAcceptorRule(int state, string symbol, Expr guard, int[][] lookahead)
 {
     int symb_id = GetId(symbol);
     int k = ranks[symb_id];
     if (state < 0 || lookahead == null || lookahead.Length != k ||
         Array.Exists(lookahead, B => (B != null && Array.Exists(B, b => b < 0))))
         throw new AutomataException(AutomataExceptionKind.RankedAlphabet_InvalidAcceptorRuleArguments);
     FuncDecl func = constructors[symb_id];
     ExprSet[] termSets = new ExprSet[k];
     for (int i = 0; i < k; i++)
     {
         termSets[i] = new ExprSet();
         if (lookahead[i] != null)
         {
             for (int j = 0; j < lookahead[i].Length; j++)
                 termSets[i].Add(tt.Z.MkInt(lookahead[i][j]));
         }
     }
     var acc = new TreeRule(tt.Z.MkInt(state), func, guard, null, termSets);
     return acc;
 }