This is a basic implementation of a Prolog interpreter in OCaml with REPL support. The interpreter follows standard Prolog IO syntax where clauses, facts, rules and terms have their usual definition.
The implementation consists of a lexer lexer.mll
, a parser parser.mly
, an REP loop toyprolog.ml
and the core unification and substitution engine a6.ml
.
- The project contains a makefile that generates an executable toyprolog.
- The executable can be run as
./toyprolog inputfile
whereinputfile
should contain all facts and rules to be loaded before execution. - The project also contains a sample prolog script based on the Harry Potter universe family trees. Its called
hogwarts.pl
and contains lots of interesting facts and rules.
make
./toyprolog sample-prolog-codes/hogwarts.pl
?-brother(X,ginnyWeasley).
X = ronWeasley;
X = georgeWeasley;
X = fredWeasley;
X = percyWeasley;
X = charlieWeasley;
X = billWeasley;
false.
?-ancestor(X,harryPotter).
X = doreaBlack;
X = charlusPotter;
X = violettaBulstrode;
X = cygnusBlack;
X = ursulaFlint;
X = phineasNigellusBlack;
X = lillyPotter;
X = jamesPotter;
false.