"Warmup" Programming Assignments

Choose one or more of the following and implement in a language of your choice.

  1. Parse a simple language. Write a program to accept or reject strings in the language with the following production rules.

  2. Download these Prolog programs: permute.pl, maze.pl, maze2.pl, and parse.pl

  3. Run each program and understand what each is doing, how it is working. This will be explained in class.
    Use "prolog" for Gnu-Prolog
    consult('file.pl'). This loads the file into Prolog.
    See sample Prolog queries listed below. Try each, and make up some of your own.

  4. Implement permute, maze2.pl, and/or parse.pl in a language of your choice.

More detail:

| ?- consult(permute).   This loads the file permute.pl

| ?- permute([a,b,c], X).
X = [a,b,c] ? ;   The semicolon means "search for another solution"
X = [b,a,c] ? ;
X = [b,c,a] ? ;
X = [a,c,b] ? ;
X = [c,a,b] ? ;
X = [c,b,a] ? ;
(10 ms) no      The "no" means there are no more solutions
| ?- 

Here's a map of the maze:

   ---------------------------
   |          |              |
   |     d           c       | 
   |          |              |
   -----   ----------   -----
   |   |      |              |
   |   |      |              |
   |   |      |              |  
   | f     e          b            a
   |   |      |              |
   |   |      |              |
   -------   -----------------
   |          |
   |     g    |
   |          |
   |          |
   -----------

Room g currently has the phone.
Problem: How do you travel from room a to whichever room has the phone?
Sentence rules for parse.pl:
sentence --> noun_phrase, verb_phrase.
noun_phrase --> determiner, noun.
verb_phrase --> verb, noun_phrase.
verb_phrase --> verb.
determiner --> [the].
noun --> [apple].
noun --> [man].
verb --> [eats].
verb --> [sings].

Problem: Determine whether a given input stream is a valid sentence.
Ex. the man eats the apple YES
    the apple eats the man  YES
    man eats apple NO
    the man eats apple NO
  1. Sample Prolog queries for maze.pl:
  2. Sample Prolog queries for maze2.pl:
  3. Sample Prolog queries for parse.pl