How do I parse boolean logic?
- by d03boy
I need to write a boolean logic parser which will translate the boolean logic language to a SQL WHERE clause.
The order of the operands will always be in the correct order (with value on the right).
Here is a relatively simple example. There could be nested parentheses and the use of NOT operators, etc.
(CACOUNT=01 OR CACOUNT=02 OR CACOUNT=03 OR CACOUNT=05
OR CACOUNT=07 OR CACOUNT=09 OR CACOUNT=12 OR CACOUNT=13 OR CACOUNT=18)
AND Q4=1 AND NAME=TIMOTHY
Here is what the WHERE clause would resemble.
WHERE (
EXISTS (
SELECT 1 FROM MyVerticalTable b
WHERE b.Key=a.Key AND b.Key='CACOUNT' AND b.Value='01'
)
)