Parsing a formula

This is a discussion on Parsing a formula within the C Programming forums, part of the General Programming Boards category; Hello everyone, I need assistance in parsing a mathematical formula that is input by the user. Say a user inputs ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    1

    Parsing a formula

    Hello everyone,

    I need assistance in parsing a mathematical formula that is input by the user. Say a user inputs the following; 4*(370-345)+12.

    How would I go about parsing such a string? We would have no idea how many numbers or operations the person enters, within a set character limit.

    Any hints would be much appreciated. Thanks in advance.

  2. #2
    Registered User
    Join Date
    Jun 2004
    Posts
    277
    Maybe you should take a look on this http://www.gnu.org/software/bison/ maybe it is too much for what you need but at least a look won't hurt.

  3. #3
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125
    Quote Originally Posted by ashkya
    Hello everyone,

    I need assistance in parsing a mathematical formula that is input by the user. Say a user inputs the following; 4*(370-345)+12.

    How would I go about parsing such a string? We would have no idea how many numbers or operations the person enters, within a set character limit.

    Any hints would be much appreciated. Thanks in advance.

    Off the top of my head, you'd need to pull it all into a string. You'd need to know your operators (*,+,-,parens) and find them.... I'd say the stuff before, after and between the operators are the things you'd probably figure are numbers.

    I might be wrong, but at least it might get you going in the right direction.....
    Mr. Blonde: You ever listen to K-Billy's "Super Sounds of the Seventies" weekend? It's my personal favorite.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parsing for Dummies
    By MisterWonderful in forum C++ Programming
    Replies: 4
    Last Post: 03-08-2004, 05:31 PM
  2. how to change char to formula
    By kosong in forum C Programming
    Replies: 2
    Last Post: 06-09-2003, 05:31 AM
  3. Math formula (js -->C++)
    By Demon1s in forum C++ Programming
    Replies: 20
    Last Post: 05-02-2003, 06:22 AM
  4. Formula string conversion
    By Gr3g in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2002, 09:28 PM
  5. I hate string parsing with a passion
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 03-19-2002, 07:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21