prog1 - Program 1: Prolog Interpreter CSC 7101, Spring 2011...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Program 1: Prolog Interpreter CSC 7101, Spring 2011 Due: 8 April 2011 Reading Please read: “Describing PROLOG by its interpretation and compilation,” by Jacques Cohen. It appeared in Communications of the ACM , volume 28, number 12, December 1985, pages 1311–1324. The Assignment Your assignment is to design and implement a simple Prolog interpreter in the programming language ML. Your interpreter will implement Prolog with the following noteworthy characteristics: The interpreter will print out just the Frst solution found. The interpreter will use a depth-Frst search, and search the database in the order in which the assertions were made. The interpreter will implement the occurs check. The interpreter will have the special, predeFned relation symbols init , fail , and ! (cut), but none of the others found in other implementations, like atom , = , etc. The main function of your interpreter must be named Prolog and take one argument of type HornClause (this data structure is deFned below). Your interpreter takes one clause at a time and performs one of three actions: 1. adds a clause to a database, 2. determines a solution to a query, or 3. clears the entire database. All but the second item are easy. Implementing a query requires writing an ML function to perform uniFcation and an ML function to implement the search on the database of facts and rules. An ML algorithm for uniFcation appears in Ryan Stansifer’s ML Primer , but it has a minor error. The interpreter must search the search space in a depth-Frst manner and retrieve the Frst solution, if one exists. We ask that Prolog respond to a query by printing the query and the solution exactly as in the following template: query:vv a clause A solution: a solution A After the word query , two spaces follow the colon after “query.” If no solution exists at all for the query, then print "No" after printing the query. ±or a solution (if one exists) show the bindings of all the variables occurring in the query (in the order that they appear in the clause from left to right, no duplicates). The format of a solution has the following form: 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
a variable name 1 A = a value 1 A a variable name 2 A = a value 2 A . . . If there are no variables in the query, you must still print the heading “ solution: ”. The function Prolog should print “ assert:vv ” followed by the clause whenever a clause is added to the database. When the database is cleared, the string “ Database erased. ” should be printed. ML
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/31/2011 for the course CSC 7101 taught by Professor Baumgartner,g during the Spring '08 term at LSU.

Page1 / 5

prog1 - Program 1: Prolog Interpreter CSC 7101, Spring 2011...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online