ot: parsing math equations

Owen Patrick Smith ender3rd at WPI.EDU
Mon Jun 9 20:06:17 EDT 2003


the parenthesies and order of operations makes infix notation a pain to
parse automatically.  Look into pre/post-fix notation. it looks wierd and
takes a bit to get used to but its much easier to parse.  If you insist on
using infix try a series of regexps. Find the first set of parens and run
the algorithm recursively on just the parenthsied statement. Once you've
run out of parens to find then evaluate the highest priority operations.
repeat until you've run finished the whole string.  Basically if you're
just trying to get some help with homework consider Maple, Mathematica or
similar, its probably easier.

HtH,
Owen

On Mon, 9 Jun 2003, Tyler Spivey wrote:

> sorry if this's off topic, but here goes:
> i'm writing a program in python to do varius math things.
> factoring, radicals, etc. but my major limitation is that it can't
> do anything with algebra equations.
> 2x^2+3x+4x-x+3y
> etc...
> would a regular expression be the answer for breaking these down into there
> component parts?
> or do I need a full-blown parser for doing that?
> probably  the parser - but i'm not sure if any python based solutions exist.
> they do, but I'm not sure if they are what i want.
> i don't want to do any complex coding. this's just a spare-time project for
> getting homework done faster, and i don't want to spend hours and hours on
> it. it's currently topped almost 10k, but most of that are the docs
> contained in one very long tripple-quoted string.
> and all this coming from the guy who previously hated python without really
> trying it first...
>
>
> _______________________________________________
> Speakup mailing list
> Speakup at braille.uwo.ca
> http://speech.braille.uwo.ca/mailman/listinfo/speakup
>
>
>







More information about the Speakup mailing list