Dice roll grammar lexer

Hi! I was thinking about building a dice roll “interpreter” with a variation of the grammar you can see here. I’m not sure what are my options are… I heard about NimbleParsec and erlang leex but I’m a bit confused on how to use those to achieve what I want.

I was thinking about starting with basic operations like +, -, *, / and (, ) for grouping expressions. In the end, it’s kind of a calculator with extra-steps :sweat_smile:.

Any advice for me?

That page isn’t exactly small, can you summarize which part of it exactly do you have in mind?

Hi @dimitarvp!

Thanks for the heads up…
I didn’t mean the whole thing, it was just an example :sweat_smile:.
I want to start with basic dice notation, for example:

  • NdN
  • NdN + N; NdN - N; NdN * N; NdN / N
  • NdN + NdN; NdN - NdN; NdN * NdN; NdN / NdN
  • ((NdN) * 2) + NdN

And so on… “Basic” operations include only: +; -; *; / and (; ) for grouping expressions.
The order is not important, so something like N + NdN or 2 * 2 + (NdN + 3) should still be parsed.

I intend to expand it after with other modifiers, but first I need to wrap my head around it.
There’s another page that seems to be a little bit more concise on the topic here.

You might want to study https://github.com/slapers/ex_sel

It implements basic math notation with nimble parsec

1 Like

Thanks @axelson this will certainly be useful :smile:.
NimbleParsec’s syntax seemed a little daunting to me at first, it’s good to have more real world examples.

1 Like