If you want to reinvent the wheel here, start by reading through Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp by Peter Norvig. It has working code examples on what you want. Especially relevant are chapters 6 (Tools), 11 and 12 (Logic Programming and Prolog Compiler), and 16 (Expert Systems). It should not be too hard to pull out the code you need from this book.
Brainbench MVP for Perl