Whenever I'm home alone, I like to let my mind wander and think about
Excel formulas in POI.  (do I need to get a life?  perhaps, but my wife
says we can't afford it right now)

So I've been thinking on how we might implement formulas:

two stacks and a list

operators     operands          results


For Formula -> RPN-tokens 

Example walkthough of algorythm 

As you move through the formula poke the operation on the operation
stack and read via PEMDAS order until your done, for every operation
determine the number of operands you need and grab them.  In the event
of 3 + 3 + 4 :

since there are no parenthesis, you'll take the first operand, tokenize
and plug it onto the stack, next the + operation: tokenize and plug it
on to the operation stack, find the next operand and plug it onto the
operand stack.  You've got a queued operation so you move the tokens
over to the results list in operand,operand,operation order.

----
3 * (3 + 4)

You find a 3 tokenize and shove it onto the operands, a * tokenize and
shove it onto the operators stack, see the ( next so you shove it onto
the operations stack, see the 3 tokenize and shove it onto the operands
stack, see the + tokenize and shove it onto the operations stack, see
the 4 and put it onto the operands stack, see the )

You pop off the next operation, the +, it takes two so you throw the two
operands to the results list followed by the operation, you pop the next
operation which is the open parenthesis so you throw only the closed
parenthesis onto the results stack (one token for both), you pull the
next operation, discover its binomial, the last thing you did was a
parenthesis so you don't need two operands, you just shove the remaining
operand onto the results list and the operation along with it.

thoughts? 
--

For RPN -> Formulas 

Start at the left and just move right, any place there are parenthesis
engulf it and move out.  Same basic method in reverse, only hard thing
is we'll have WAY MANY MORE possible correct things.  Lets not support
legacy stuff (stuff excel won't write in new sheets) for this release at
least.

-Andy



-- 
http://www.superlinksoftware.com
http://jakarta.apache.org/poi - port of Excel/Word/OLE 2 Compound
Document 
                            format to java
http://developer.java.sun.com/developer/bugParade/bugs/4487555.html 
                        - fix java generics!
The avalanche has already started. It is too late for the pebbles to
vote.
-Ambassador Kosh

Reply via email to