By creating a set of rules, it is possible to do logic programming in Prolog like this. You can build a grammar (or download one) for a particular domain, create a knowledge base and then query it. After defining your grammar you could do something like:
bob is a parent of tim.
mary is a parent of bob.
?- X is a grandparent of tim.
X = mary
?- jim is a parent of bob.
false