View Full Version : Expression Manipulator v0.01

04-07-2003, 05:37 PM
Yes, it's still very alpha. Just an expression parser, really. Attached is the source code. Basically, at the prompt, you type an expression (not an equation):

5x + 6x^2 + 7^yz - (x+(x+(x+3)^2))

This is valid input. The division symbol '/' doesn't work properly, but it should be a quick fix. Variables may be any length. Be sure to seperate variables with an asterisk (*). Negative signs are assumed to be attached to a term unless it's followed with a space.

The combine_like_terms() function currently works badly and unpredictably.

Any suggestions, comments, or critisism is appreciated.

Functions don't work
To raise something to a power, make sure it is right after the '^' sign.
If in doubt, surround it with parentheses.
I hope to support a wide variety of things, like equations, derivatives, integrals, substitution, etc
The code is very messy. If you need to, ask for clarification.

04-07-2003, 05:44 PM
wow, i'll try it out later. cool, i was thinking about writing a calculus class but i never had the time.

04-07-2003, 05:56 PM
Hopefully the next release will be rock solid. This one features memory leaks, lack of function support, no division symbol, and a ton of messy code.

04-07-2003, 06:40 PM
Pretty cool, but I agree with ygfperson.

I really should write a calculus class. I'm always having to write a specialized one in some of my AI programs that deal with fractals. Or at the very least, I should do just a fractal class, with new data types like REAL. Do you think I should send it in for the source code section of the site.

04-07-2003, 08:42 PM
hey ygf, can u post a executable for the prog, my compiler is screwd and i can;t compile it....i'm getting like 20+ errors

EDIT: btw, i was using BC++ 5.01

04-07-2003, 09:24 PM
What kind of errors?

I can't post an executable due to the file size limitation.

Attached is v0.02: now with division and function support. Memory still leaks though.

04-07-2003, 09:24 PM
forgot to attach...

Here's the class structure if anyone's interested:

Expression -> One


Factor -> Numeral -> Float
Factor -> Function
Factor -> Factor_Expression
Factor -> Variable

One is a special case of expression, meant to be used as a primitive so that the program doesn't loop indefinitely when figuring out powers. Expression contains a vector array of Terms. Each term contains a vector array of Factor pointers.

Function is basically a string of the functions name and an expression of the function's inside. Float contains a double-precision value. There was an Integer class but it was removed because it was too difficult to manage both Float and Integer at the same time. Factor_Expression is basically an Expression contained in a regular factor. Variable is just a string containing the variable's name.

Every Factor contains an Expression pointer to deal with powers.

04-07-2003, 09:54 PM
here's a screen shot of the errors

EDIT: i missed a few in the bottom, but those r the general errors

04-07-2003, 11:33 PM
cool. I had to write something like this just last week for school, except we also had strings and sets as operands

04-08-2003, 04:59 AM
Commander, try removing the std:: beginnings of any variables or functions in question. You can remove any 'std::cerr' statement entirely; that's just for debugging purposes.

Here's version 0.03. I've fixed the memory management (much easier than I thought). Functions work fine, so do other primitives. So this should be a pretty stable release. I've renamed the zip file to keep them from getting mixed up with the other two. My next release won't be for a few days, at least.