gnewitall
Programmer
- Sep 15, 2005
- 6
I need to create a form that allows users to enter a formula then parses and evaluates it to return a 1 or 0 on the backend. I am struggling with the logic of how to evaluate the string by storing the contents of the inner most parenthesis first, pair it with the appropriate operator then continue this process until the formula is evaluated. I guess there will be an if statement, but not sure how to put it together. I will need to call some custom functions as indicated below with sin[y], cos[z], f[x]. Please help guide me.
Given a user entered string like,
$formula = "((a > (2 * b)) and (sin[y] < cos[z])) or (f[x] >= 1)";
BTW, I know I will need error checking for unmatched parenthesis and allow only certain characters for security reasons. I feel I can do this part of the program, no problem.
Given a user entered string like,
$formula = "((a > (2 * b)) and (sin[y] < cos[z])) or (f[x] >= 1)";
BTW, I know I will need error checking for unmatched parenthesis and allow only certain characters for security reasons. I feel I can do this part of the program, no problem.