예제 #1
0
        /// <summary>
        /// Creates a weighted alternative of rules.
        /// </summary>
        /// <param name="rules">
        /// Set of rule to choose from alternatively.
        /// </param>
        /// <remarks>
        /// <para>
        /// The <see cref="IRule.Weight"/> property of each rule is used to
        /// weight the probability to choose the rule.
        /// </para>
        /// <code>
        /// [EBNF]
        /// rule := A | B | C where A is chosen with P(A)=A.Weight / ABC.Weight
        /// and ABC.Weight = A.Weight + B.Weight + C.Weight
        ///
        /// [C#]
        /// IRule rule = Rules.WeightedAlt(A,B,C);
        /// </code>
        /// </remarks>
        /// <returns>
        /// An <see cref="AlternativeRule"/> instance implementing
        /// the alternative rule choosing.
        /// </returns>
        public static AlternativeRule WeightedAlt(params IRule[] rules)
        {
            AlternativeRule alt = Alt(rules);

            alt.Selector = new WeightedRandomRuleSelector();
            return(alt);
        }
예제 #2
0
 /// <summary>
 /// Creates an alternative of rules.
 /// </summary>
 /// <param name="rules">
 /// Set of rule to choose from alternatively.
 /// </param>
 /// <remarks>
 /// <code>
 /// [EBNF]
 /// rule := A | B | C
 /// 
 /// [C#]
 /// IRule rule = Rules.Alt(A,B,C);
 /// </code>
 /// </remarks>
 /// <returns>
 /// An <see cref="AlternativeRule"/> instance implementing
 /// the alternative rule choosing.
 /// </returns>
 public static AlternativeRule Alt(params IRule[] rules)
 {
     AlternativeRule alt = new AlternativeRule();
     foreach(IRule rule in rules)
     {
         alt.Rules.Add(rule);
     }
     return alt;
 }
예제 #3
0
        /// <summary>
        /// Creates an alternative of rules.
        /// </summary>
        /// <param name="rules">
        /// Set of rule to choose from alternatively.
        /// </param>
        /// <remarks>
        /// <code>
        /// [EBNF]
        /// rule := A | B | C
        ///
        /// [C#]
        /// IRule rule = Rules.Alt(A,B,C);
        /// </code>
        /// </remarks>
        /// <returns>
        /// An <see cref="AlternativeRule"/> instance implementing
        /// the alternative rule choosing.
        /// </returns>
        public static AlternativeRule Alt(params IRule[] rules)
        {
            AlternativeRule alt = new AlternativeRule();

            foreach (IRule rule in rules)
            {
                alt.Rules.Add(rule);
            }
            return(alt);
        }