Skip to content

Latest commit

 

History

History
57 lines (48 loc) · 1.51 KB

grammar.md

File metadata and controls

57 lines (48 loc) · 1.51 KB

Grammar

  1. expressionsimple_expression repeat | fcount ( die , condition_list )
  2. repeat{ num } | ε
  3. simple_expressionterm simple_expression'
  4. simple_expression'addop term simple_expression' | ε
  5. termfactor term'
  6. term'mulop factor term' | ε
  7. factornum factor' | [ num d num addop extrema ] |( simple_expression ) | min | max
  8. factor'd num | ε
  9. minfmin ( simple_expression , simple_expression )
  10. maxfmax ( simple_expression , simple_expression )
  11. condition_listcondition condition_list'
  12. condition_list', condition condition_list' | ε
  13. conditionrelop num

tokens

  1. num → [1-9][0-9]*
  2. d → d|D
  3. addop → + | -
  4. mulop → * | /
  5. relop → > | < | >= | <= | =
  6. extrema → MIN | MAX
  7. min → min
  8. max → max
  9. count → count

machines

  1. whitespace
  2. num
  3. d
  4. relop
  5. extrema
  6. min
  7. max
  8. count
  9. catchall

example valid strings

1d20 + 4 + min([2d4-MAX], 3)

max(10, 1d20 + 4) # evaluate 2 simple_expressions, return max value
min(2d20, 15)

max(10, max(1d10, 1d20))

[4d6 - MIN] # roll 4 six-sided dice, subtract the lowest value
[4d6 - MAX] # roll 4 six-sided dice, subtract the highest value

count(4d6, >4)
count(10d6, >=5, =1, =6, <=4)