[Tutor] newbie evalpostfix [writing a infix parser in Python]

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Dec 11 19:31:56 EST 2003



On Fri, 12 Dec 2003, j hansen wrote:

> How do I modify evalpostfix to parse from left to right so that it
> follows the order of operations?

Hi j,


Are you referring to the 'evalpostfix' from 'How To Think Like a Computer
Scientist':

    http://www.ibiblio.org/obp/thinkCSpy/chap18.htm

Please don't force us to guess.  *grin* Try to make it easier for people
to help you with your question.


It sounds like you'd like to try writing an 'infix' parser.  Infix parsers
are actually a little bit harder to do than a postfix parser, because of
the whole issue of operator precedence (as well as parenthesized
expressions).  If you don't need to handle parenthesized expressions, then
it won't be so difficult.


Will you try to handle things like:

   (a + b) * c

as well as

   a + b * c

?

If you do try to handle the parenthesized expressions, then you're in for
some work.  *grin* Tell us more about the problem.



Good luck to you!




More information about the Tutor mailing list