in reply to converting a boolean syntax

If you only need a mechanical conversion, then something like this might be a starting point

#! perl -sw use strict; my @stack; while( <DATA> ) { print; s[NOT\s+][-]g; 1 while s[(?<!\+)(\b\w+\b)\s+AND\s+][+$1 AND ]g or s[\s+AND\s+(?<!\+)(\b\w+\b)][ AND +$1]g; s[\sAND\s][ ]g; s[\s+OR\s+][ ]g; print $_, $/; } __DATA__ word1 AND word2 word1 OR word2 word1 AND NOT word2 (word1 AND NOT word2) OR word3 word1 AND word2 AND word3 (word1 AND word2 OR word3) AND NOT (word4 OR word5) (word1 AND (word2 OR (word3 AND word4 AND NOT word5)) AND word6) OR wo +rd7

Output

D:\Perl\test>268325 word1 AND word2 +word1 +word2 word1 OR word2 word1 word2 word1 AND NOT word2 +word1 -word2 (word1 AND NOT word2) OR word3 (+word1 -word2) word3 word1 AND word2 AND word3 +word1 +word2 +word3 (word1 AND word2 OR word3) AND NOT (word4 OR word5) (+word1 +word2 word3) -(word4 word5) (word1 OR (word2 OR (word3 AND word4 AND NOT word5)) AND word6) OR wor +d7 (word1 (word2 (+word3 +word4 -word5)) +word6) word7

If you want to syntax check the input before conversion then you have more work to do. Regexp::Common::balanced would be a good starting point for extracting the sub-expressions.

Might be fun to code, but it would need a much fuller explanation of what is leagal in the output format.

Eg. is -(sub condition) legal?

What about (+word1 +word2) (+word3 +word4)?

The toughest part is probably giving meaningful error messages when you encounter syntax errors.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller