public function calculate() {
    // reset the rolls array
    $this->rolls = array();

    // throw rolls and replace 'xdy' dice notation with results
    $this->equation = preg_replace_callback("/(?P<count>\d+)d(?P<sides>\d+)/i", "self::_expand_equation", $this->input);

    // calculate result
    $this->result = @eval("return $this->equation;");

    return $this;
  }