It's been maybe 25 years since I wrote a prefix(algebraic) to postfix (RPN) routine to parse an algebraic expression. I would have to work on this for awhile to get it working.
Example using stack:
(2+3)*5 results in: push 2, push 3, add, push 5, multiply
This requires an op precedence table.
I think you are better off with some form of Perl eval if the actual equation is unknown until runtime.
As another technique, for 8 variables, you can make an array of say 256 entries, use one bit for each variable, precalculate the results for the 8 variables and use a simple lookup table for the result.
This is also possible with a Perl hash table. Just calculate values where the 8 or whatever variables describe a "true" result.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.