PLDA Homework 4: Prolog interpreter

Write an interpreter for a Prolog subset.

A Prolog program is composed of several clauses. Clauses can be facts or rules. A rule has the form

Head :- Body .
where Head is a predicate, and Body is a list of one or more predicates separated by commas. A fact has the form
Predicate .
and is equivalent with the rule Predicate :- true . Predicates are written over terms, which are constants, variables, or functions of terms. Variables start with uppercase and constants with lowercase letters.

The meaning of a clause is that the clause head is true if all the predicates in the body are true.
Evaluation of a goal is done by unifying it with the head of a rule, and then evaluating the subgoals in the rule attempting to make them true.

Before unification, the variables in the rule head and body have to be renamed to fresh variables.

A definition for terms and a parser is given. Compile with ocamlc -pp camlp4o ML files and use from the command line.
Options: a parser that also works with the OCaml toplevel. Another parser that also accepts numeric constants (still interpreted as strings).
A module for printing clauses.


Marius Minea
Last modified: Tue Nov 15 8:30:00 EET 2011