Re: Parsing a Dice Roll String

new topic     » goto parent     » topic index » view thread      » older message » newer message

> Subject: Parsing a Dice Roll String
> 
> 
> posted by: cklester <cklester at yahoo.com>
> 
> I'm writing a die roller and need to be
> able to parse a dice function string.
> 
> Some examples:
> 
>    3d6+5 (roll 6-sided die 3 times, add 5 to sum)
>    4d6-Lowest (roll 6-sided die 4 times, discard lowest die)
>    4d6-Highest (roll 6-sided die 4 times, discard highest die)
>    2d10*3-3d4 (roll 10-sided die twice, multiply by 3, then subtract
>                the result of rolling a 4-sided die three times)
>    5d12/10 (roll 12-sided die five times, divide result by 10)
> 
> I actually tried starting this function, but couldn't get through it.
> Anybody else want to try? 
> 
> The current roller and a die-roll graphing program
> can be found here: http://www.cklester.com/euphoria/
> 
> Thanks!!!
> -=ck

Well, I'd expect Matt's matheval.e to be able to handle this with minor text 
translation.
My understanding of your pb is: parse a string like `
roll ::=
({<number>d<sides>[<operation>(roll | <reference> | <constant>])[<operation>])+

where <reference is any of "Lowest" or "Highest" (any more?).
What's to be stored in list_Rolls? The roll outcome?
<number> and <sides> are positive integers, <constant> is an atom..
<operation> is any of +-*/ (any more?)
Did I get it?

Regards
CChris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu