Hmmmm.... I hadn't thought about in-place substitutions. My original assignment was an infix-to-postfix calculator, and the precedence order I listed was required for that algorithm to work.

I did find a few bugs in your solution. I realize your code was just an example, and I appreciate the insight, I just want to make sure anyone that downloads it realizes there are issues. For example, your code wouldn't allow for multiple @[] operators at the same level (i.e. &3>4@[1d6]+&1>4@[1d100]). Division should be integer. Negative numbers (and thus unary -) need to be implemented. There's no general syntax checking.

I went ahead with the in-place substitution idea and should have some code ready to post soon. I've addressed all of the above issues and a few more. There are still issues with precedence lists, though.... with this method it is impossible/difficult for operators to share the same precedence. For example, normally something like 5*20/3*3 should equal 99, but in this case it comes up 11 (100/9). That's not a problem as long as it's documented.


In reply to Re: Re: Dice calcs? by Anonymous Monk
in thread Dice calcs? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.