How about this solution with some modifications to fit your current needs?
Or, as a crude workaround, you could use the Rhino as a JavaScript engine, simply change textual representation of operations to operators like &&
, ||
, etc. and have the JS engine evaluate and give you the results.
If you are interested only in the output values of the expressions, the above should be sufficient.
If you need to devise your own algorithm, than you'll need to write a parser yourself which is a tedious work, but feasible.
Let the user enter all the expression along with the operators (it will not make that much of a different from an implementation point of view). You'll of course need to validate the input. Data you'll need to deal with are either 0
, 1
, parentheses (which trigger result stacking/unstacking) and operators themselves (well, additionally, there are whitespaces, but you should simply ignore them).
Basically, evaluating from the left to right, you take the first data parameter (either 0
, 1
) and put it in the current result. Then you read the operator and apply it to the result and the next piece of data. An so on until you reach the end of the input. Upon encountering parentheses the simplest thing to do is to have the parser recursively call itself with the expression inside the parentheses (you should match them up) and treat the return value as an ordinal piece of data.