Thread: Expression Manipulator v0.01

  1. #1
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490

    Expression Manipulator v0.01

    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):
    Code:
    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.
    Last edited by ygfperson; 04-08-2003 at 04:59 AM.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    wow, i'll try it out later. cool, i was thinking about writing a calculus class but i never had the time.

  3. #3
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    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.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    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.

  5. #5
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    801
    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
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: [email protected] []*[]

  6. #6
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    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.

  7. #7
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    forgot to attach...

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

    Expression -> One

    Term

    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.
    Last edited by ygfperson; 04-08-2003 at 04:59 AM.

  8. #8
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    801
    here's a screen shot of the errors

    EDIT: i missed a few in the bottom, but those r the general errors
    Last edited by Commander; 04-07-2003 at 09:58 PM.
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: [email protected] []*[]

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    cool. I had to write something like this just last week for school, except we also had strings and sets as operands
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

  10. #10
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    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.
    Last edited by ygfperson; 04-08-2003 at 05:12 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with making a Math Expression DLL
    By MindWorX in forum C Programming
    Replies: 19
    Last Post: 07-19-2007, 11:37 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 09:15 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Expression Evaluator Contest
    By Stack Overflow in forum Contests Board
    Replies: 20
    Last Post: 03-29-2005, 10:34 AM