So I am new to prolog and I am suppose to implement a type checker. How exactly should I go about it? This would be an example:
String s; int i; i = s.length(); // OK (example given in the homework)
When I asked the professor how things will be input, it would look something like this:
instance(s, string).
Thats great, except if this is done, the unification for i is lost at the close of the query, so if I were to make a say, equals fact and call it like so,
equals(i, s, '.', 'length').
how can i check what i is. So I am just having a hard time knowing where to start. Its a homework, so just want some advice, help on kind of understanding how to go about my first prolog project. Thanks in advance.
EDIT: Assignment
Write a Prolog program that can type check the method calls for a given Java program
according to the JLS . The fact base can be any encoding of the methods defined in any
non-trivial Java program you have written, plus, minimally, those listed below. In query
mode, it must check potential matches; for example allowing “println(string).” You need
not encode those JLS rules that you don’t need. (One of the examples given is above.)
I intended what follows as a starting point. Here is my formalisation:
means that string is an available type for a variable to be an instance of
means that the infix operator = takes two arguments of same type and returns nothing.
means that
Xis an instance of typeYTo test things out, I created a list of “statements” contained in my variable
Inputof mytest/0predicate. Then I recursively test out if things are well. You have to implement the third clause as a recursive call to find out if types are ok in expressions now.What I did atm is that in my first main
check/2clause, I handleinstance/2terms, and in the following one, all the rest.I hope it’ll help to get you started.