Thursday, March 30, 2017

Pseudobot: More Sophisticated Dice Parser

Originally, Pseudobot's dice roller simply parsed an expression that could be described as "Dice Adds" EG:
\d+d\d*([+-]\d*)?
That is a regular expression and doesn't fully allow for many possible combinations of dice rolling expressions someone might need quickly executed, so I rewrote the parsing logic to use a context free branching grammar. Thanks to some help last night, I rooted out all the major bugs and most of the minor ones, so feel free to roll dice with addition, subtraction, division, multiplication, exponents, and parentheses.
Oh, and behind the scenes, just for fun, I made this tool that converts the trees into graphviz syntax so you can see what it looks like for quicker debugging. The image is an example of the equation: 1d -2d +3d(4d/1d). And for layman, basically, the equation is solved in the correct order by solving the lowest pieces first and moving up.
Parsed version of 1d-2d+3d(4d/1d)

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...