I got interested in lexers and parsers because they sounded fun. With that knowledge, I build a dice-rolling “compiler”, a tool that takes a string of instructions for rolling dice and returns an array of results.
For example, the input 2d6
would return something like [2, 3]
, meaning two six-sided dice were rolled and landed on 2 and 3.
Of course, it gets more complex than that. A more advanced command like 20d6 rr3+ sv3+
would roll twenty six-sided dice, reroll any 3s, 4s, 5s, or 6s (rr3+
), and then remove all 1s and 2s (sv3+
).
— random.txt