dogs OR cats OR "flying fish" OR (shrimp AND squid)
into an array where the 1st element is "OR", 2nd is "dogs", 3rd is "cats", 4th is "flying fish", and 5th is a reference to another array whose 1st element is "AND", 2nd is "shrimp", and 3rd is "squid".
If you're not beginning to feel at least a little confused you're smarter than I. But anyway, the program should be able to do this even if there are more or less terms, and even if there are parenthetical groups inside parenthetical groups, so long as the terms directly inside any one parenthetical group are connected by the same operator (i.e. either "AND" or "OR").