[UPHPU] Fwd: Shunting Yard to convert from infix to postfix?
Nathan Lane
nathamberlane at gmail.com
Tue Sep 23 13:35:59 MDT 2008
I have been working on a text mode calculator program for some time, and
have come to the conclusion that my system of objects and classes is too
complex. I want to make this calculator simple in the inner workings. Right
now, I do several passes on an infix-style equation in order to evaluate it.
1. Parse infix-style equation into tokens and define the tokens by type
1. For example, if I find '23' then I save it as a token of type
Number and with a value of 23
2. Also if I see '(' then I save it as a token of type Open
Parenthesis and with a value of '('
2. Convert to polish-postfix-style equation by parsing the tokens using
the Shunting Yard
Algorithm<http://en.wikipedia.org/wiki/Shunting_yard_algorithm>,
and changing the order (I use an operator stack to help with this -- see
https://personalcalculator.dev.java.net/#howpcworks)
3. Evaluate the polish-postfix-style equation, which is simple
I just think that my system of object-based conversion is very complex. But
I want to handle everything myself, i.e. not use any language-built-in
evaluate functions. Is there another method aside from the Shunting Yard
Algorithm that anybody has used or heard of for converting from infix to
postfix? Should I just attempt to evaluate the infix equation as is? Does
anybody have any ideas on how to accomplish the task of making this simpler?
--
Nathan Lane
Home, http://www.nathandelane.com
Blog, http://nathandelane.blogspot.com
--
Nathan Lane
Home, http://www.nathandelane.com
Blog, http://nathandelane.blogspot.com
More information about the UPHPU
mailing list