         throw "Bad unary operation: #{op}"
 
   roll: (dice, sides) =>
+    console.log dice
+    return ZERO if dice == 0
+    if dice < 0
+      throw new DiceError "Cannot roll a negative number of dice."
     result = (randInt(1,sides) for i in [1..dice]).reduce (t, s) -> t + s
     @dice_rolled.push
       dice: dice

      when '#'
        (times, ast) =>
          count = @interpret_subroll times
          throw new DiceError "Cannot roll #{count} times, minimum 1."
          console.log count
          for _ in [1...count]
            @interpret_subroll ast
          @interpret_node ast

class DiceError extends SyntaxError
  constructor: (@message) ->
    @name = "DiceError"

ZERO =
  type: "Number"
  value: 0

randInt = (min, max) ->
  values = max - min + 1
