Kyle Silver

Dice Rolling Notation: Now With Recursion!

A Recursive Dice Roller

Common dice rolling options are supported: – Roll a single die: d6 – Roll multiple dice: 3d8 + 4 – Roll many, keep highest: 2d20k1 - 3 – Roll many, keep lowest: 3d10kl2 – You can use parentheses: 3 * (2d6 + 4) – Add many rolls together: 3d8 + 2d6 + 2
But! In addition to these normal operations, you can also nest expressions with arbitrary depth – (2d6)d8(d10 + 7)d(4d6 * 2)k(d6) - 2((5d4)d3)d2

This was a fun little project that I made to learn about programming languages and parsers—as well as WebAssembly. If you’re having fun playing around with the dice roller, stick around for a breakdown on how I made it.


Published 2023-03-18