CSCI.4430/6430 Programming Languages Fall 2014
Programming Assignment #1

This assignment is to be done either individually or in pairs. Do not show your code to any other group and do not look at any other group's code. Do not put your code in a public directory or otherwise make it public. However, you may get help from the TAs or the instructor. You are encouraged to use the LMS Discussions page to ask questions so that other students can also answer/see the answers.

Natural Language Processing with Building-Blocks

You are to take an existing Prolog program and extend it to add new features. is a program that allows the user to manipulate a set of blocks on a table. The user can place blocks on other blocks or on empty spots on the table using natural language. A simple grammar can parse certain commands such as "Please place block a on block b." or "I want a on b.". The parser converts these sentences into simple commands (e.g. on(a,b)). There are also limitations, because a block cannot be moved if it is under another block or if you are trying to move it on top of a covered block or onto the table when there are no free table positions. To start the read-eval-print loop, execute "place_blocks." in Prolog after the appropriate files are loaded. This assignment was changed slightly from the example described in section 7.3 of an extensive Prolog tutorial. The assigned extensions are the same, while some details are somewhat different (the tutorial works toward an animation which is not part of this assignment).

Starting files: (must be loaded first) and

Part 1. Complete the following idiom extensions.

(a) Formulate a new question idiom, one of whose scripts is "What is block X sitting on?".

(b) Formulate a new question idiom, one of whose scripts is "Which blocks are on the table?".

(c) Formulate a new command idiom, one of whose scripts is "Put all of the blocks in a single pile.". This is an interesting idiom, because the abstract meaning is ambiguous -- that is, there could be more than one abstract meaning for this idiom. Assume that one abstract meaning is no better or worse than another; just generate one of them as "the" meaning.

(d) Formulate a new command idiom, one of whose scripts is "Put the block on top of X on top of block Y." (or on the table). This will involve interpreting the definite description ("the ...") acurately.

(e) Formulate a new command idiom, one of whose scripts is "Put the highest block on top of block y." (or on the table). This will involve interpreting the definite description ("the ...") acurately.

Part 2. Reading command / question scripts.

Implement a program that executes command or question text-based "scripts". The user can type any commands or questions from the original grammar or the extended grammar of Part 1. The scripts should allow access to the most recently accessed block using the keyword "result". Basically, wherever "result" is used, it should work as if "result" was replaced by the block letter that was last queried. See script.eng for an example script. If the setup before is

 a  d
then after the script is run you should have
 a  d  c

Some notes: "result" should be bound to the last valid block that is the result of a question or command as follows.

The value of result should remain fixed throughout other questions / commands. result has no initial value. result should remain fixed if queries fail.

Extra Credit (up to 25% bonus).

Implement a planning program to move from one block world state to another. Your extension is to take the input and generates the output as specified below.

Input: (A) Initial locations of blocks, (B) Final locations of blocks
Assuming (A)->(B) is reachable by executing combinations of the commands implemented in Part 1 and 2 (e.g., no blocks will disappear).

Output: The list of operations needed to change the locations of the blocks to go from (A) to (B). For the example above, the output may look like: [on(c,table),on(b,d)]

Reading Material:

The assignment builds on an example from section 2.19 and chapter 7 of the tutorial at However, if you are new to Prolog, you might want to start with the tutorial at Be sure to read chapters 7 and 8 in the second tutorial which talk about natural language processing in Prolog.

Due Date:
Received Time Grade Modification
before Sunday, 09/14, 11:59PM +10%
before Monday, 09/15, 11:59PM no modification (on time)
before Tuesday, 09/16, 11:59PM -10%
before Thursday, 09/18, 11:59PM -25%
after Friday, 09/19, 12:00AM not accepted

Grading: The assignment will be graded mostly on correctness, but code clarity / readability will also be a factor (comment, comment, comment!).  See the professor or TAs, if you have ideas for other extensions for this assignment and would like extra credit for implementing them.

Submission Requirements: Please submit a ZIP file with your code, including a README file. In the README file, place the names of each group member (up to two). Your README file should also have a list of specific features / bugs in your solution. Your ZIP file should be named with your LMS user name(s) as the filename, either or Only submit one assignment per pair via LMS.