|
|
|
Your skill will accomplish what the force of many cannot |
|
| PerlMonks |
Re^2: Using overload to parse arithmetic termsby blokhead (Monsignor) |
| on Feb 07, 2006 at 14:41 UTC ( #528524=note: print w/ replies, xml ) | Need Help?? |
|
To expand (and generalize) on this a bit, let each type of operation have a precedence. Then as you walk the expression tree, you need to parenthesize operations that have a lower precedence than the expression they appear within. A good way to do this is via OO, representing your operation types as subclasses: Then you just call the display method on an Op tree. For example, And you can see how easy it would be to add new types of operations, due to the beauty of subclassing. blokhead
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||