in reply to Re: Re: Dice calcs?
in thread Dice calcs?
1. To get it to do the multiple @ operators at the same level you need to
Then replace the 'Precedence 5' regexp with:use Regexp::Common
$term=~s/(\d+)@($RE{balanced}{-parens=>'[]'})/rpt($1,$2)/eg;
2.To get it to do the * and / from left to right, change 'Precedence 3' to this single regexp:
and change 'Precedence 4' to$term=~s/(\d+)([\*\/])(\d+)/int(eval("$1$2$3"))/eg;
$term=~s/(\d+)([+-])(\d+)/eval("$1$2$3")/eg;
Hope these help you with your efforts. There is still no syntax checking but I figure you can handle stopping people from putting 3*+/4. Oh, and you probably want to handle negative numbers before 'Precedence 4'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Dice calcs?
by Anonymous Monk on Sep 19, 2002 at 14:11 UTC |