/// <summary>
        /// Parses the specified dice expression and converts it into a
        /// Dice instance to perform oprations on.
        /// </summary>
        /// <param name="expression">String expression to parse</param>
        /// <param name="config">Dice config to tell whether this result will be bounded or unbounded</param>
        /// <param name="dieRoller">Die roller to use</param>
        /// <returns>Dice result</returns>
        public DiceResult Parse(string expression, DiceConfiguration config, IDieRoller dieRoller)
        {
            this.config = config;

            // first clean up expression
            expression = this.CorrectExpression(expression);

            // then break the expression down into tokens.
            List <string> tokens = this.Tokenize(expression);

            // finally parse and evaluate the expression tokens
            return(this.ParseLogic(expression, tokens, dieRoller));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DiceResult"/> class.
        /// </summary>
        /// <param name="expression">dice expression rolled</param>
        /// <param name="value">calculated value of the results</param>
        /// <param name="results">List for results for each term in dice expression</param>
        /// <param name="rollerUsed">Define die roller used to get the results</param>
        /// <param name="config">Dice config to tell whether this result will be bounded or unbounded</param>
        public DiceResult(string expression, int value, List <TermResult> results, string rollerUsed, DiceConfiguration config)
        {
            this.DiceExpression = expression;
            this.DieRollerUsed  = rollerUsed;
            this.Results        = results.ToList();

            bool boundedResult = expression.Contains(FudgeDiceIdentifier) ? false : config.HasBoundedResult;

            this.Value = boundedResult ? Math.Max(value, config.BoundedResultMinimum) : value;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DiceResult"/> class.
 /// </summary>
 /// <param name="expression">dice expression rolled</param>
 /// <param name="results">List for results for each term in dice expression</param>
 /// <param name="rollerUsed">Define die roller used to get the results</param>
 /// <param name="config">Dice config to tell whether this result will be bounded or unbounded</param>
 public DiceResult(string expression, List <TermResult> results, string rollerUsed, DiceConfiguration config)
     : this(expression, results.Sum(r => (int)Math.Round(r.AppliesToResultCalculation ? r.Value * r.Scalar : 0)), results, rollerUsed, config)
 {
 }