Programming Assignment 2 (due midnight 08/27/13)

Penalty for late submission: 10% less credit/day.

Implement, document (i.e. provide specifications), and test all your code. Make sure all your code is thoroughly tested and runs on tux.

  1. (24 points) Create a random Binary Search Tree in Haskell and ML. Insert one million random numbers into an empty BST. You can download a random set of numbers here or create your own. Do not try to sort the numbers to get a balanced tree. Insert these numbers one by one into an initially empty BSTs and then compute the number of nodes and the heights of the resulting trees.
    1. (12 points) Implementation in Haskell
    2. (12 points) Implementation in ML
  2. (24 Points) Implement the following in Prolog:
    1. (12 points) Create a min function that finds the minimum element in a list.
      min(X,L) is true when X is the minimum element of the list L.
      Example:
              | ?- min(10,[1,2,3,4,5]).
                              
              no
              | ?- min(1,[1,2,3]).
                              
              true ? 
                              
              yes
              | ?- min(X,[2,5,1,4,2]).
                              
              X = 1 ?
                          
    2. (12 points) Create a sentence function in prolog.
      Sentence(L) is true when the list L contains a valid sentence.
      For this assignment, a valid sentence will be defined as follows.
      Sentence -> noun_phrase verb_phrase
      noun_phrase -> article noun
      verb_phrase -> verb noun_phrase
      Nouns -> boy, girl, dog, cat
      Verbs -> sees, pets
      Articles -> a, the

      Examples:
              | ?- sentence([the,boy,pets,a,dog]).
                              
              yes
              | ?- sentence([the,girl,sees,a,cat]).
                              
              yes
              | ?- sentence([girl,pets,boy]).
                              
              No
                          
  3. (10 Points) Lab 5 - Introduction to Parser Generators
  4. (42 Points) Create a Parser Generator for Regular Expressions

    Write a parser for regular expressions using Python with the parser generator PLY. Your parser will take a regular expression as input. It will output a DOT file with the NDFA that accepts the regular expression. (more on DOT files below)
    You can download PLY from http://www.dabeaz.com/ply/. PLY is used for the example parser in Lab 5.

    Input Format
    Your parser should except regular expressions built up from union "|", concatenation (juxtoposition), and closure "*" and symbols coming from the alphabet of single lower case letters. You should also allow "(" and ")" for grouping. The precedence of these operators should be: closure highest, concatenation next highest and union lowest. The binary operators for union and concatenation should be left associative. You should model your grammar after the mathmatic grammar from Lab 5. (Hint: The precedence of the math operators was exponent highest, multiplication next highest, and addition lowest.)

    Here are some examples:

    Note that the comments are not part of the actual input. Nor are you responsible for parsing comments.

    Your program will read from stdin; there will be one expression per line.

    Output Format
    Your output should be a DOT file with the NDFA for the regular expression. We recommend Graphviz for viewing your dot files. It can be downloaded from http://www.graphviz.org/. On tux you can convert DOT files to images using the dot program. For example, you can convert output_0.dot to 0.gif by entering
    dot -Tgif -o0.gif output_0.dot
    You should create a DOT file for each line of input. The first regular expression should be output as 0.dot. The next expression parsed should be named 1.dot. Continue accepting strings until the user enters Ctrl-D for end of file. You do not need to implement a quit command.
    Here are some example REGEXP to NDFA examples:
    a|b View DOT File View Image
    a(b*) View DOT File View Image

CS 360 Programming Assignment 2 Submission Guidelines

  1. Assignments must be submitted via Email.
    Email the Assignment to mwb33@drexel.edu
    CC a copy to Professor Nowak kn33@drexel.edu
  2. The Title of the Email must be CS 360: Programming Assignment 2
  3. Attach all solutions in a single zip or tar.gz file. Name the file username_a2.zip or username_a2.tar.gz where username is your drexel login. For example, mine would be mwb33_a2.zip.
    Here is a useful website for making zip/tar.gz/etc in linux: http://www.simplehelp.net/2008/12/15/how-to-create-and-extract-zip-tar-targz-and-tarbz2-files-in-linux/
  4. In the body of the email list all the files you are submitting. Give the name of the compressed file and a list of the contents. If any files are missing/corrupted, then I will know what you submitted.
  5. Submit one text file for each question. You should submit the following files:
    1. BST.ml - ML Implementation of Question 1
    2. BST.hs - Haskell Implementation of Question 1
    3. min.pl - Minimum in Prolog
    4. sentence.pl - Sentence in Prolog
    5. regparser.py - Regular Expression Parser using PLY.
    6. You may include supporting files for your python implementation, for example, if you wrote a special class or library and stored it in a different file.
    7. test_input.txt - (Optional) a test file for the python parser. python regparser.py < test_input.txt
    8. Readme.txt - A readme file explaining how to run and test all your files.
  6. Each file should contain:
    1. Your Name
    2. Comments documenting all functions included in the file
    3. Your function definition
    4. Tests for your functions
  7. Submit a readme file containing the following:
    1. Your Name
    2. Email Address
    3. Example Execution Traces testing each of your functions
  8. All your code MUST run on tux.cs.drexel.edu.