Class to help validate an arithmetic expression

I'm looking for classes that can assist the validation of an arithmetic expression. For example,  it can capture that
(3+9) *  4 - 2)  is not valid.  And would be good to create a tree that represent this expression.

Do I have to manage  the task by myself?
JeabSMJAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbormannCommented:
yes ,but do hunt around for free code somewhere .....
0
JodCommented:
You need some sort of well formed expression parser.

There are plenty of java parsers out there. JavaCC comes to mind for example.

With JavaCC you write a grammar that describes the format of the data you want to parse and it then generates the program to do it for you.

You could also try putting the data into an XML tree. There is free stuff to do this for you to but this may require a bit more work.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mbormannCommented:
hey man , i suddenly remembered I had done a simple Reverse Polish notation (postfix) using a simple 'C' code but I have forgotten totally abt it.
I only remember that it used a stack and u could implement the operations like add, substract etc... enforcing precedence without parentheses.
this is what compiler do internally ,if i remember correctly from college days.

Please search for it as I feel that it will suit u to a 't' .

Jod, wot say matey?
0
JodCommented:
Yep, postfix notation (or for that matter prefix) will work with only a stack - the problem is to get normal expressions such as the one above into postfix form.

For that you would still need a parser I'm afraid so JavaCC is still your best option unless someone has some free code that converts between infix notation (such as that above) to postfix notation.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.