Describes a symbolic tree transduction rule.
Inheritance: AcceptorBase
Example #1
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);
        }
Example #2
0
        internal TreeRule MkIdRule(RankedAlphabet A)
        {
            if (!IsAcceptorRule)
            {
                throw new AutomataException(AutomataExceptionKind.MkIdRule_RuleIsNotAcceptorRule);
            }

            Expr[] args = new Expr[this.lookahead.Length + 1];
            args[0] = A.AttrVar;
            for (int i = 1; i <= this.lookahead.Length; i++)
            {
                if (!(this.lookahead[i - 1].IsEmptyOrSingleton))
                {
                    throw new AutomataException(AutomataExceptionKind.MkIdRule_RuleIsNotFlat);
                }
                args[i] = (this.lookahead[i - 1].IsEmpty ? A.tt.Z.MkApp(A.Trans, A.tt.identityState, A.ChildVar(i))
                                                       : A.tt.Z.MkApp(A.Trans, this.lookahead[i - 1].SomeElement, A.ChildVar(i)));
            }
            var new_output = A.tt.Z.MkApp(symbol, args);
            var new_rule   = new TreeRule(this.state, this.symbol, this.guard, new_output, this.lookahead);

            return(new_rule);
        }
Example #3
0
        internal TreeRule MkIdRule(RankedAlphabet A)
        {
            if (!IsAcceptorRule)
                throw new AutomataException(AutomataExceptionKind.MkIdRule_RuleIsNotAcceptorRule);

            Expr[] args = new Expr[this.lookahead.Length + 1];
            args[0] = A.AttrVar;
            for (int i = 1; i <= this.lookahead.Length; i++)
            {
                if (!(this.lookahead[i-1].IsEmptyOrSingleton))
                    throw new AutomataException(AutomataExceptionKind.MkIdRule_RuleIsNotFlat);
                args[i] = (this.lookahead[i-1].IsEmpty ? A.tt.Z.MkApp(A.Trans, A.tt.identityState, A.ChildVar(i))
                                                       : A.tt.Z.MkApp(A.Trans, this.lookahead[i-1].SomeElement, A.ChildVar(i)));
            }
            var new_output = A.tt.Z.MkApp(symbol, args);
            var new_rule = new TreeRule(this.state, this.symbol, this.guard, new_output, this.lookahead);
            return new_rule;
        }
 /// <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;
 }