If you don't need to do it yourself, you may use Wolfram|Alpha API, it has a plenty of boolean-algebra-related features, like converting to various normal forms and so on. If that's a homework and you should invent your own wheel, you may use some parsing tools (or invent your wheel, again) to tokenize the string and then apply the set ob boolean algebra rules: http://mathworld.wolfram.com/BooleanAlgebra.html
I think I should make this more concrete - you can't solve this problem in general case without writing that set of rules in your code (hardcoding it). The most concise way is to use something like ANTLR to produce a boolean-rules-constrained language and then just feed your inputs to it.