Dear Sir,
My project was to create a complete interpreter for Prolog written in OCaml, one of my favorite programming languages with Java. This interpreter takes in clauses and returns the answer on a query. I have attached three files out of which the first is a byte file which you can directly run by using the following command: "ocamlrun Run.byte". You need to have OCaml installed in your system to test this project. A very simple sample input and output snippet would be:
(* Facts and rules *)
a(1).
a(2).
b(X,Y) :- a(X), a(Y).
(* Query *)
b(X,Y)
X -> cons 1;Y -> cons 1;True
X -> cons 1;Y -> cons 2;True
X -> cons 2;Y -> cons 1;True
X -> cons 2;Y -> cons 2;True
Cut has also been implemented in the project. The code can be found by unzipping "Prolog Interpreter.zip" which has three files, namely, Afourlex.mll(a lexer for Prolog); Afourparse.mly(the parse for Prolog which contains the Interpreter and backtracking functions) and Maina4.ml(the main function which makes the interpreter work). The complete code where interpretation has been done is, as I mentioned, Afourparse.mly.
Also, I have worked on another project where I created a compiler-cum-interpreter for a sample generic language(which could be familiar to C++, Java or even Prolog). This was an advanced project where the entire compiler, interpreter and the stack machine were written in Prolog itself. This project made me extremely comfortable with Prolog and the intricacies of the language. I also got a feel of how a compiler and an interpreter could be written FOR any language IN any language. The source code of the same can be found in "Prolog.pl" which can be run using SWI Prolog as well as gprolog. I would like to apologize that Prolog.pl is not so well documented and modularized to readability as yet as the project is still not totally complete.
I would like you to take a look at these files, which have been my main stepping stones in the world of compilers and interpreters. Better yet, both these projects involved Prolog helping me gain great insight into the language. I feel I can do this project by rewriting the parser to support UTF-8 with which I am very familiar. Could you tell me which what kind of a patch would you like ? Any other comments or requests are also welcome.
Regards,
Rishabh Garg