It does sound this might be done easier on prolog - once you get your head around the paradigm :-)
I've used SWI Prolog in college. It's a pretty complete implementation with can be integrated in Emacs if you're into that kind of thing, and it's free (basically LGPL with some additional exceptions to let you create non-free software with it).