Skip to content

Dice Notation

Olivier Grégoire edited this page Jul 17, 2020 · 2 revisions

The dice notation is a system to represent different combinations of dice in the SRD. It uses a simple algebra-like syntax such as 2d6+3.

Notation

Die rolls are given in the form AdX. A and X are variables, separated by the letter "d", which stands for die or dice.

  • A is the number of dice to be rolled.
  • X is the number of faces of each die.

For example, if a rule would call for a roll of 1d4 this would mean, "roll one four-sided die."

3d6 would mean, "roll three six-sided dices". Commonly these die values are added together.

To this basic notation, an additive modifier can be appended, yielding expressions of the form AdX+B. The plus is sometimes replaced by a minus sign ("−") to indicate subtraction. B is a number to be added to the sum of the rolls. So, 1d20−10 would indicate a roll of a single twenty-sided die with ten being subtracted from the result.

(Adapted from Wikipedia's Dice Notation page)

Parsing Dice notation

The dice notation used in the System Reference Document 5.1 is very basic and doesn't go beyond the addition and subtraction, except for a very few cases such as critical hits which fortunately aren't referenced in the data themselves.

So here's an example ANTLR grammar that you can use to parse all the dice notations you can find in the data. If you find a notation in the data and this grammar doesn't parse it, please file an issue.

grammar DiceNotation;

expression
  : dice
  | number
  | modifier
  | operation
  ;

operation
  : operand (OPERATOR operand)*
  ;

operand
  : dice
  | number
  | modifier
  | '(' expression ')'
  ;

dice
  : quantity=COUNTABLE? ('d' | 'D') sides=COUNTABLE
  ;

number
  : COUNTABLE
  | '0'
  ;

modifier
  : SPECIFIC_MOD
  | UNDEFINED_MOD
  ;

SPECIFIC_MOD
  : 'STR'
  | 'DEX'
  | 'CON'
  | 'INT'
  | 'WIS'
  | 'CHA'
  ;

UNDEFINED_MOD
  : 'MOD'
  ;

COUNTABLE
  : NON_ZERO_DIGIT DIGIT*
  ;

OPERATOR
  : [+-]
  ;

fragment NON_ZERO_DIGIT
  : [1-9]
  ;

fragment DIGIT
  : [0-9]
  ;

WS
  : [\t\r\n ]+ -> skip
  ;
Clone this wiki locally