How about this (example used is "(A AND B) OR (C OR D NOT E) OR Q"):
- Break the statement into smaller ones on the joiner --
AND, OR, NOT -- which are not inside parent expression.
That will yield:
{ OR <-- { (A AND B) , (C OR D NOT E) } , OR <-- { Q } }.
- Go thru to each of the component of the broken down
tokens, to search for the joiner as above, giving:
{ AND <-- { A, B } , OR <-- { C , D , NOT E } }.
- Do the above for all other sub components, till all are
exhausted.
- Ending up w/...
{ OR <--
{ AND <-- { A , B }
, OR <--
{ C , D
, NOT <-- { E }
}
}
, OR <-- { Q }
}
- Last step would be add the appropriate signs (or nothing at all) based on parent joiner,
which can be easily done in a loop.
Well, that is what currently comes to mind, bugs expected.
Updated (Jun 24 2003) the parsed expressions as
after adding "OR Q" in the example, forgot to correctly
update the hierarchy.