in reply to When the only tool you have is a screwdriver...

Last night I was doing a bit of light reading which just might be of help to you. In the book Mastering Algorithms with Perl, Chapter 9: Strings, p.399, there is an example of developing a top-down parser to translate a query into a regular expression. For example, it will take a query like:
abc and not (def or ghi)
and turn it into:
/abc/ && ! ( /def/ || /ghi/ )
The example is very thorough, and the finished code is very simple, so if you can get hold of the book I am sure you could adapt it to your needs.

Replies are listed 'Best First'.
Re^2: When the only tool you have is a screwdriver...
by ExReg (Priest) on Oct 08, 2015 at 18:03 UTC
    I have the book right above me. And it is the one that I had not looked in. Fantastic! I think I will have to bury myself in it for a while and see what inspiration I can get.