JeabSMJ
asked on
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?
(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?
yes ,but do hunt around for free code somewhere .....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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?
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.
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.